How to store results from while loop and sentinel in python?

后端 未结 3 660
礼貌的吻别
礼貌的吻别 2021-01-26 10:08

been working on this for hours, thought i had it down but it turns out i have it all wrong.

The assignment is to

Write a program that computes your sem

3条回答
  •  孤独总比滥情好
    2021-01-26 10:37

    If you're storing the input as integers, you probably want a dict. You'd do something like this:

    numberOfInputs = 10
    names = ["Quiz 1", "Quiz 2", "Program 1", "Exam 1", "Final Exam"]
    d = {}
    for name in names:
        i = int(input(name.rjust(4)))
        if i < 0:
            quit()
        d[name] = i
    # calculate the ave
    for name in d:
        print(name)
    print("Average: " + ave)
    

    You'd check if you need to quit every time and you'd also have a fairly intuitive way of accessing the data.

提交回复
热议问题