This is my first SO question.
I am teaching myself to code using Python (and subsequently django). I am working on developing a website that allows local sailing regattas to create groups and track their results. Although this will eventually be a django project using a database, I wanted to write a simple script to 'sketch' the logic.
Objective: I would like a user to be able to create a Race Group, add boats to this group, and print various items.
Current Code: I have written the basic script that allows users to add boats to an existing race group:
#basic program logic to add boats to an existing race group;
#existing race group:
shediac = {
'location':'Shediac NB',
'year':2020,
'boats': boats
}
#default boat list to pass into the race group
boats=[
{'name':'name1','owner':'owner1','handicap':0.00},
]
#loop to take user input when adding new entries
answer=input('do you want to add a boat?: Y/N').upper()
while answer == 'Y':
name = input('enter the boat name: ')
owner = input('enter the boat owner''s name: ')
handicap = input('enter the boat handicap: ')
boats.append({
'name': name,
'handicap': handicap,
'owner': owner,
})
# get user input again to retest for the while loop
answer=input('do you want to add a boat?: Y/N').upper()
#prompt user to select information to display:
while true:
what = input('what do you want to view: NAMES / OWNERS / HANDICAP / EXIT:
').lower()
if what == 'names':
for boat in shediac['boats']:
print(boat['name'])
elif what == 'owners':
for boat in shediac['boats']:
print(boat['owner'])
elif what == 'handicap':
for boat in shediac['boats']:
print(boat['handicap'])
else:
print('see you next time')
Challenge:
How do I get a user to create a new race group
How do I take the user input to generate the name of the new race group
I am using a dictionary for each race group, and passing in a list of boats (dictionaries containing various key value pairs). The existing code works to add boat entries to the existing race group (dictionary).
If my approach is entirely wrong, I welcome any better solutions! My primary interest is understanding how to approach such a problem.
Thanks.