Introduction to Python

elif

Nested conditions can get pretty deep very quickly. That makes reading the code difficult and programmers tend to avoid having many nested conditions (and having too much-nested code in general). Python provides a utility elif that helps in avoiding else and then if statements:
if name == 'Alice':
	print('Hey there!')
else:
	if name == 'Bob':
		print('How are you doing?')
	else:
		if name == 'Anna':
			print('Hello, Anna')
		else:
			print('Hi!')
if name == 'Alice':
	print('Hey there!')
elif name == 'Bob':
	print('How are you doing?')
elif name == 'Anna':
	print('Hello, Anna')
else:
	print('Hi!')
These two programs do exactly the same. They print personalized greeting messages and contain many if/else statements. Yet, the first one has many layers of nested if/else blocks, while the second uses elif statements which stands for else if.

Challenge

Having a grade which is a number from 0 to 100, we would like to know what would that grade correspond to in the US Letter grading system (A, B, C, D, and F).
Note: Do not use only if statements with range checks. Use elif when checking for another condition.
Numeric grade
Letter grade
90-100
A
80-89
B
70-79
C
60-69
D
0-59
F
Write a program that would do the conversion.
Input
Output
81
B
100
A
 

Constraints

Time limit: 1 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue