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

后端 未结 3 699
礼貌的吻别
礼貌的吻别 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:31

    You don't want to have a fixed number of quizes or projects. Instead, use a loop for each of those types of scores, so you can keep asking until they user doesn't have any more scores to enter.

    I'm not going to write the whole thing for you, but here's one way to handle the quizes:

    quiz_scores = []
    
    while True:
        score = int(input("Quiz #{} ----- ".format(len(quiz_scores)+1)))
        if score == -1:
            break
        quiz_scores.append(score)
    
    quiz_total = sum(quiz_scores) - min(quiz_scores) # add up the scores, dropping the smallest
    

    There are other ways you could do it. For instance, instead of building a list of scores, you could keep track of a running sum that you update in the loop. You'd also want to keep track of the smallest score you've seen so far, so that you could subtract the lowest score from the sum at the end.

提交回复
热议问题