This is a program to get a student mark, as an input from user and print its grade based on the following criteria:
if mark>=80 print 'A'
if mark between 70-80 print 'B'
if mark between 60-70 print 'C'
if mark between 50-60 print 'D'
if mark < 50 print 'F'

How do I fix this code when e.g someone gets 75 it says you got a B C D ?

percent = 85

if percent > 80:
print("You got an A!")
if percent > 70:
print("You got a B!")
if (percent >60):
print("You got a C!")
if (percent > 50):
print("You got a D!")
print("You got an F!")

Recommended Answers

All 4 Replies

For everything other than the first if use elif.

For future posts, please use the code tool, </>, to insert code blocks.

mark = input("Enter marks: ")

if mark >= 80:
elif mark >= 70:
elif mark >= 60:
elif mark >= 50:
To learn more about Python, I would suggest visiting: Learn Python.

commented: Spamming that site will be noticed. +0

What you posted is not valid Python. To be valid you have to add indentation and to add indentation you need to post the code using the code block tool </>.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.