-1

So my professor for python assigned an exercise which was to create a program to accept a user input or "score" and create an if else loop with an if else nested loop inside the first loop to check if the score is greater than or equal to 80. If that's satisfied, print a statement saying "you passed." and if the score is equal to 90 or more, then it should say"you got an A." and if the score is below an 80, it should say "you failed."

so far, this is the code I was able to come up with. And it runs up until the score entered is anything equal to or more than 90.

userScore = int(input('enter score:\n'))
if userScore < 80:
    userScore = int(input('you failed. Try again:\n'))
    if userScore == 80 or userScore > 80:
        print(f'good job, you got a B.')
    elif userScore >= 90:
        print('you got an A')
else:
    print('enter a differnt score')
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
  • Do `while True:`. Ask for your input. If it succeeds, do `break`. Otherwise print your error, and the loop will ask again. – Tim Roberts Jan 08 '22 at 04:15
  • If-else isn't a loop. It's a statement for making decisions – Python learner Jan 08 '22 at 04:33
  • Does this answer your question? [Asking the user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) – Tomerikoo Jan 08 '22 at 10:16

3 Answers3

1

as per your question your code should be :

score = int(input("Please enter your score: "))
if score >= 80:
    print("You passed.")
    if score >= 90:
        print("You got an A.")
else:
    print("You failed.")

Jay Patel
  • 1,098
  • 7
  • 22
0
while(1):
    score = int(input("Please enter your score: "))
    if score >= 80:
        print("You passed.")
        if score >= 90:
            print("You got an A.")
            break
    else:
        print("You failed.")
  • While this code snippet may solve the problem, it doesn't explain why or how it answers the question. Please [include an explanation for your code](//meta.stackexchange.com/q/114762/269535), as that really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – Luca Kiebel Jan 08 '22 at 11:00
0
while(1):
score = int(input("Please enter your score pal: "))
if score >= 80:
    print("You passed the exam.")
    if score >= 90:
        print("You got an A in the exam.")
        break
else:
    print("You failed the exam.")
Raman
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 08 '22 at 08:51