1. while.py
i = 1
while i <= 6:
i = i + 1
print(i)
2. break.py
i = 1
while i <= 6:
i = i + 1
print(i)
if i == 3:
break
3. continue.py
i = 1
while i <= 6:
print(i)
i = i + 1
if i == 3:
continue
print("happy")
Using a WHILE loop:
- Count up from 1 to 10.
- Count backwards from 50 to 40.
- Develop a game called "Unmatch", where the aim is to count how many times 2 dice can be rolled without matching.
To play, 2 dice are rolled using random.randint(1,6)
, and if the rolls don't match, the score can be increased by +1. If the rolls do match, the score gets reset to 0.
Try and keep a high score to see how many "unmatches" you can get in a row.
- print a list of even numbers between 40 to 0 (counting down) using a loop. When I reach the number 20, it should print a message to the screen "HALF WAY THERE". When i reach the numbers 10 and 30, it should say "ONE QUARTER OF THE WAY" and "THREE QUARTERS OF THE WAY THERE" respectively.