0
import time, os, sys
import random

st = 0.05
def sp(str):
  for letter in str:
    sys.stdout.write(letter)
    sys.stdout.flush()
    time.sleep(st)
  print()


black = ("\u001b[30mඞ")
red = ("\u001b[31mඞ")
green = ("\u001b[32mඞ")
yellow = ("\u001b[33mඞ")
blue = ("\u001b[34mඞ")
magenta = ("\u001b[35mඞ")
cyan = ("\u001b[36mඞ")
white = ("\u001b[37mඞ")
run_game = True
char = random.choice(["imposter", "crewmate"])
color = random.choice([black, red, green, yellow, blue, magenta, cyan, white])
nums = ['1', '2', '3']
task = {
    "cafeteria" : ["Clean Chute", "Download Data", "Fix Wiring"],
    "admin" : ["Upload Data", "Swipe Card", "Fix Wiring"]
    }

print(black, red, green, yellow, blue, magenta, cyan, white)
sp(f"You are {color}\u001b[37m and you are {char}.")
sp("\n\nThe game will start in 3 seconds")


def game():
    while run_game:
        choice = input("\nYou are a crewmate and are in cafeteria. What do you want to do:\n[1] Do tasks in cafeteria.\n[2] Call an emergency meeting.\n[3] Go to a different room.\nEnter the number (1-3)>>> ")

        while choice in nums:
            if choice == '1':
                task_cafe = input("Here are the tasks you can do in cafeteria:\n")
                 


if char == 'crewmate':
    game()

How do I delete one of the elements in the list defined to 'cafeteria' in the dictionary 'task'. Also after I display the input of "task_cafe" I want to print all elements in the list defined to 'cafeteria' in the dictionary 'task' in each line. Like this:

Here are the tasks you can do in cafeteria:
[1] Clean Chute
[2] Download Data
[3] Fix Wiring
Enter the number (1-3) >>>
  • Have you read about tuple unpacking in Python? Have you looked up 'iterating through a dictionary python'? – Blake G Dec 11 '20 at 21:26
  • `for index,ch in enumerate(task["cafeteria"],1): print(f"[{index}] {ch})` - deleting is handled in the dupe. You should concentrate on _one_ question (these are several) and reduce your code to a [mre]. For deletion, 2 lines of code would have been sufficient. For asking how to print from a dict, 2-3. – Patrick Artner Dec 11 '20 at 21:29
  • can u tell me a simpler method please. – Abdullah Rajput Dec 11 '20 at 21:29

0 Answers0