I'm teaching myself programming and Python. So, this is probably a ridiculously obvious question to many. I'm trying to take an input that includes 1) student name and 2) an indeterminate amount of grades. I want to assign the grades to a student and allow for as many student and grade combos as possible.
My problem is I can't figure out how I continuously receive user input without overwriting previous user input. I've tried a for loop, a while loop, using a list of lists with lists [ [student, [grades] ], [student, [grades] ] ] and a dictionary with a list { student : [grades], student : [grades] }
def main ( ) :
name_prompt = input ( '\n Enter the student's name: ' )
grade_num = int ( input ( '\n Enter the number of grades you want to enter: ' ) )
grade_array = list ( )
## access_dict = dict ( )
count = 0
while count < grade_num:
grade_prompt = float ( input ( '\nEnter grade: ' ) )
grade_array.append ( grade_prompt )
access_array = [ name_prompt, grade_array ]
## access_dict [ name_prompt ] = grade_array
## access_array = [ access_dict ]
## thought I might be able to use append or __setitem__ after the first loop to add item to end of list/dict and thus not overwrite
if count >= 1:
access_array.append ( name_prompt, grade_array )
#access_dict.__setitem__( name_prompt, grade_array )
count += 1
rerun = input('\n Do you want to enter another student? ')
if rerun in ('y','Y','yes','Yes','ok','OK','okay','yup','yah','yep','yeah','indubitably bro'):
main ( )
Also, is there a Stack Exchange for beginners?