-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhowManyRounds.py
72 lines (62 loc) · 2.38 KB
/
howManyRounds.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def process_user_input(user_input):
"""Using conditional statements, this function will generate the proper output based on the user's input"""
# If user_input is a number, convert from string to int
desired_number_of_rounds = int(user_input)
# Run if user inputs 0
if desired_number_of_rounds == 0:
print('Take care!')
exit()
# Run if user input is greater than 5
elif desired_number_of_rounds > 5:
print("Try a smaller number, preferably between 1 and 5")
return ask_for_rounds()
# Run if user inputs a number greater than 1
elif desired_number_of_rounds > 1:
print(f"Fantastic! We'll do {desired_number_of_rounds} rounds of box breathing.")
# Run if user inputs 1
else:
print(f"Excellent! We'll do {desired_number_of_rounds} round of box breathing.")
# Return the user input
return desired_number_of_rounds
# Ask for Rounds function
def ask_for_rounds():
"""This function asks the user to input their desired number of rounds, and returns the input"""
# Ask user to input their desired number of rounds
print('How many rounds of breathing would you like to do?')
user_input = input(
'Enter a number between 1 and 5, or type "0" to exit the program: ')
# Run if user_input contains only numbers
if user_input.isnumeric():
num_of_rounds = process_user_input(user_input)
# Return the user input
return num_of_rounds
else:
# Checks if user_input is a negative number or not a number
while not user_input.isnumeric():
if user_input == 'zero':
num_of_rounds = process_user_input(0)
# Return the user input
return num_of_rounds
elif user_input == 'one':
num_of_rounds = process_user_input(1)
# Return the user input
return num_of_rounds
elif user_input == 'two':
num_of_rounds = process_user_input(2)
# Return the user input
return num_of_rounds
elif user_input == 'three':
num_of_rounds = process_user_input(3)
# Return the user input
return num_of_rounds
elif user_input == 'four':
num_of_rounds = process_user_input(4)
# Return the user input
return num_of_rounds
elif user_input == 'five':
num_of_rounds = process_user_input(5)
# Return the user input
return num_of_rounds
else:
print("Invalid input")
return ask_for_rounds()