Nested conditions can get pretty deep very quickly. That makes reading the code difficult and programmers tend to avoid having many tested conditions (and having too much-nested code in general). Python provides utility
elifthat helps in avoiding
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/elsestatements. Yet, the first one has many layers of nested
if/elseblocks, while the second uses
elifstatements which stands for
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
elifwhen checking for another condition.
Write a program that would do the conversion.