-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patherrors_handling.py
27 lines (21 loc) · 988 Bytes
/
errors_handling.py
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
def party_planner(cookies, people):
leftovers = None
num_each = None
# TODO: Add a try-except block here to
# make sure no ZeroDivisionError occurs.
try:
num_each = cookies // people
leftovers = cookies % people
except ZeroDivisionError:
print(' input a different number of people')
return(num_each, leftovers)
# The main code block is below; do not edit this
lets_party = 'y'
while lets_party == 'y':
cookies = int(input("How many cookies are you baking? "))
people = int(input("How many people are attending? "))
cookies_each, leftovers = party_planner(cookies, people)
if cookies_each: # if cookies_each is not None
message = "\nLet's party! We'll have {} people attending, they'll each get to eat {} cookies, and we'll have {} left over."
print(message.format(people, cookies_each, leftovers))
lets_party = input("\nWould you like to party more? (y or n) ")