Is there a way to pick a event from the list and choose it so that a name will be added? events=["100m Dash"]
menu = int(input("###Welcome to the PE departments Sports Day
program\nPlease enter a number to progress through the menu:\n1.Input
events and names of students\n2.Add the winners to a text document\n3.Open
the house point tracking###"))
if menu == 1:
menu1 = int(input("Please enter a number to progress through the menu:\n1.Add an event\n2.Add an name"))
if menu1 == 2:
print events
name_1 = int(input("Which event do you want to add the name to?:"))
if name_1 == events:
name_1_1 = str(input("Please enter a name you would like to enter:"))
print(name_1_1 ,"has been added to text file: Names and Events")
file_appender = open("names.txt","w")
file_appender.write(name_1_1)
names = ["steve", "bob", "joe"]
events = {"100m Dash": names}
print(events)
name_1_1 = str(input("Please enter a name you would like to enter:"))
names.append(name_1_1)
events["100m Dash"] = names
print(events)
This is the following output:
{'100m Dash': ['steve', 'bob', 'joe']}
{'100m Dash': ['steve', 'bob', 'joe', 'robert']}
This uses dictionaries to keep track of the names by events.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.