If Statements

Often we have the need to do a comparison between two objects such as numbers. For instance, if we wanted to compare the variable “number1” to zero, we would use an if statement:

if number1 < 0:

print ('negative')

elif number1 == 0:

print ('zero')

else:

print ('must be positive!')

Note: Also see Comparison Operators.

Assignment

Write a program that prompts for two numbers, then informs us if the 1st number is less, greater than, or equal to the 2nd number.

Save as "025.py".

Assignment

Write a program that prompts for 5 grades between 0 and 100, then outputs the numerical average and the grade average (A = 80-100, B = 70-79.9, C = 60-69.9, D = 50-59.9, F < 50).

Write this program as efficiently as possible. (Think carefully about your approach!)

Save as "025a.py".

Assignment

Referring to program A1 in the 1990 (Niagara South) programming competition, write the program but amend it so it loops infinitely until the Exit option is chosen. (Note: you may need to refer to Counters and While Loops for assistance.)

Save as "025b.py".