Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Nested If Work Help
#1
Hi,

Started using Nested Ifs in my work and have made this code.

math=int(input("Enter your math score: \n"))
english=int(input("Enter your english score: \n"))
science=int(input("Enter your science score: \n"))
average=math+english+science/3
if average>50:
print("You have a score of at least 50.")
if 50<= average <= 64:
print("You have passed with a grade C.")
elif 65<= average <= 75:
print("You have passed with a grade B.")
elif 75<= average <= 90:
print("You have passed with a grade A.")
elif 90> average <= 100:
print("You have passed with a grade A*.")
else:
print("Better luck next time.")

For some reason, no matter what score I put into the variables, it just says "You have a score of at least 50." but never mentions a grade letter.

Would appreciate any help in solving this. :)
Reply
#2
We would appreciate it if you reposted your code with python tags. See the BBCode link in my signature for instructions. There may be indentation errors causing the problem, but we can't see them.

Note that your average is calculated wrong. Order of operations means that it only divides the science score and then adds the math and english scores. You need parentheses around the addition to get the right average.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Also you have error - the first condition should check that average<50, not like you do now that average>50
Reply
#4
(Oct-09-2017, 07:49 PM)buran Wrote: Also you have error - the first condition should check that average<50, not like you do now that average>50

Not based on the print statement after it ('at least 50'). Also the next if isn't an elif. That's why I want to see the indentation.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
yeah, you are right. i overlooked that next is not elif.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020