-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStars game example.py
More file actions
26 lines (23 loc) · 1007 Bytes
/
Stars game example.py
File metadata and controls
26 lines (23 loc) · 1007 Bytes
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
# Type and execute/run this program example and see
# how the while-loop only breaks when one of the two
# 'break' statements is executed. If none of them gets
# executed, the while-loop keeps on iterating. This
# program example is another great example of how
# the conditional 'if:' and 'elif:' statements work in
# conjunction with the logical operators.
while True:
try:
stars=int(input(f'How many stars would you like? ').strip())
if stars>1:
print(f'\n{stars} Stars: [',' * '*stars,f']\n\nI gave you {stars} \
Stars!\n\nI hope you enjoy your {stars} Stars...')
break
elif stars==1:
print(f'\n{stars} Star: [','*'*stars,f']\n\nI gave you {stars} \
Star!\n\nI hope you enjoy your \'One\' \
and \'Only\', single Star...')
break
elif stars==0:
print('\nSorry Hero! Zero doesn\'t count.\n')
except ValueError:
print('\nNumbers only please!\n')