Skip to content

Commit f47f515

Browse files
committed
Updated Recursion Function for Outbreak
1 parent 0c17f2c commit f47f515

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

recursion/exponential.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def main():
1616
base = input("Enter a base: ")
1717
power = input("Enter a power: ")
1818
while valid == False:
19-
2019
try:
2120
base = int(base)
2221
valid = True

recursion/outbreak.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
'''
2+
@file outbreak.py
3+
@author Morgan Bergen
4+
@date March 28 2022
5+
@brief Exercise 2: Outbreak Returns
6+
7+
Flu season is upon us and the number of people getting sick is growing.
8+
9+
On day 1, there was only 6 people had the flu
10+
On day 2, it jumped to 20.
11+
On day 3, there were 75
12+
13+
Every day since, the number of people who have the flu is equal to the last 3 days combined
14+
You will make a program that will ask the user for what day they want a count of people with the flu for. Then display the amount. You must use recursion to solve the calculation of infected for a given day. Assume the user will input a valid day.
15+
16+
day people
17+
1 = 6
18+
2 = 20
19+
3 = 75
20+
4 = 75 + 20 + 6
21+
4 = (4 - 1) + (4 - 2) + (4 - 3)
22+
x = (x - 3) + (x - 2) + (x - 1)
23+
24+
25+
'''
26+
27+
28+
29+
def main():
30+
print("OUTBREAK!")
31+
days = input("What day do you want a sick count for?: ")
32+
if int(days) == 0:
33+
print("Invalid day")
34+
else:
35+
print(f"Total people with flu: ", end="")
36+
print(outbreak(int(days)))
37+
38+
39+
def outbreak(days):
40+
if days == 0:
41+
return (0)
42+
elif days == 1:
43+
return (6)
44+
elif days == 2:
45+
return (20)
46+
elif days == 3:
47+
return (75)
48+
else:
49+
return outbreak(days - 1) + outbreak(days - 2) + outbreak(days - 3)
50+
51+
main()
52+
53+
54+
55+
56+
57+
58+

0 commit comments

Comments
 (0)