Python Mark book with multiple marks per student?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Florrianer
    New Member
    • May 2012
    • 3

    Python Mark book with multiple marks per student?

    Code:
    def markbook_list():
    
        names = []      
        marks = []      
    
        while True:     
            name = raw_input("Name: ")      
          
            if name == "exit":      
                break
            elif name == "print":     
                print "Name" + "      " + "Mark"
                for x in range(len(names)):
                    print names[x] + "     " + marks[x]
            else:
                names.append(name)      
                mark = raw_input("Mark: ")      
                marks.append(mark)
    1)Write a markbook application to read in, store and print out the marks for students

    I already did number 1 as you can see.
    How would one change the code so that it prompts the user for multiple marks per student?
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    You would use another while loop and append marks to a list until the user enters "exit" or some character that exits the loop. You might possibly want to use a list of lists, i.e
    [[name1, mark1, mark2],
    [name2, mark1, mark2, mark3]] or a dictionary. The following is pseudo-code and will not work perfectly as is.
    Code:
            else:
                 if len(interim_list):
                     master_list.append(interim_list)
                 interim_list=[name]  ## redefine it as new name only      
                 #names.append(name)
                 mark = raw_input("Mark: ")      
                 interim_list.append(mark)

    Comment

    Working...