-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloops.py
More file actions
38 lines (35 loc) · 1.17 KB
/
loops.py
File metadata and controls
38 lines (35 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# print each donut
# print("you have eaten 1 donuts.")
# print("you have eaten 2 donuts.")
# print("you have eaten 3 donuts.")
# print("you have eaten 4 donuts.")
# print("you have eaten 5 donuts.")
# print("you have eaten 6 donuts.")
# print("you have eaten 7 donuts.")
# print("you have eaten 8 donuts.")
# print("you have eaten 9 donuts.")
# print("you have eaten 10 donuts.")
donuts_eaten = 1
while donuts_eaten <= 10:
print(f"you have eaten {donuts_eaten} donuts.")
# donuts_eaten = donuts_eaten + 1
# without something that gets us closer to breaking the loop
# we end up with an infinite loop
donuts_eaten += 1
# Infinite loops can be good
while True:
print("working...")
user_input = input("Should I stop? (y/n) ")
if user_input == 'y':
print("thank you!")
# stop a loop with break keyword
break
else:
print("sigh...")
donuts_to_eat = int(input("How many donuts will you eat? "))
user_donuts_eaten = 0
while user__donuts_eaten <= donuts_to_eat:
user_donuts_eaten += 1
print(f"you have eaten {user_donuts_eaten} donuts.")
if (user_donuts_eaten == donuts_to_eat / 2):
print("you're halfway there")