Control Statemnets
Objective
Learn
- if / else conditionals
- for loops
- while loops
Reference
Essentials
Exercises
If-Else
A1 - Write if/else to print if a number if odd or even
A2 - Write if-else-if-else to print grade.
If score > 90 grade is A.
If score is between 80 and 90 then grade is B.
If score is between 70 and 80 then grade is C.
A3 - Write a ‘ternary’ operator in one line.
if score > 50 ? print(“pass”) : print (“fail”)
Loops
B1 - Write a for loop printing 1 to 10
B2 - write a for loop printing 1 to 10, but in steps of 2 (e.g. 1, 3, 5, 7, 9)
B3 - Write a while loop printing 1 to 10
B4 - Write a loop from 1 to 10 and printing odd / even numbers
Checklist
At this point, you should:
- be comfortable writing if / else statements
- writing for loops
- writing while loops