if, else, and elif Statements
Read this for more on conditional statements.
2. If-else statement
Multi-branch if-else statements
test_score = float(input("Enter test score:"))
if test_score >= 90:
print("This is an A grade!")
if 80 <= test_score < 90:
print("This is a B grade!")
if 70 <= test_score < 80:
print("This is a C grade!")
if 60 <= test_score < 70:
print("This is a D grade!")
else: print("Unfortunately this is an F grade")
test_score = float(input("Enter test score:"))
if test_score >= 90:
print("This is an A grade!")
if 80 <= test_score < 90:
print("This is a B grade!")
if 70 <= test_score < 80:
print("This is a C grade!")
if 60 <= test_score < 70:
print("This is a D grade!")
else: print("Unfortunately this is an F grade")
test_score = float(input("Enter test score:"))
if test_score >= 90:
print("This is an A grade!")
elif 80 <= test_score < 90: # only one branch will execute!
print("This is a B grade!")
elif 70 <= test_score < 80:
print("This is a C grade!")
elif 60 <= test_score < 70:
print("This is a D grade!")
else: print("Unfortunately this is an F grade")