In: Computer Science
DIRECTIONS: Complete the following Programming Exercise in
Python. Name the file Lastname_Firstname_E1.
You just started your summer internship with ImmunityPlus based in
La Crosse, Wisconsin. You are working with the forecasting team to
estimate how many doses of an immunization drug will be needed. For
each drug estimation, you will be provided the following
information:
corona.txt
39
20
31
10
42
49
54
21
70
40
47
60
- The size of the target population.
- The life expectancy, in years, of an individual in the
population.
- A file containing ages, in years, of a sample of 12 people
infected in the population.
To calculate the number of doses needed, proceed as follows:
- Calculate the average age of infection from the sample of 12
ages.
- Calculate the Base Reproduction Number (R0): ?0 = ???? ??????????
??????? / ??? ?? ?????????
- Calculate the Herd Immunity Threshold (Q) ? = 1 − (1 / ?0)
- Calculate the estimated number of doses ????? = ? ∗ ??????????
????
QUESTION: Construct a program that allows a user to enter the size
of the target population, the life expectancy of an individual in
the population, and the name of the sample file. Once this
information is obtained, perform the above four calculations and
output the result of each calculation, appropriately labeled.
Example: Enter population size: 329450000
Enter life expectancy: 78.87
Enter sample file name: corona.txt
Average Age of Infection: 40.25
Base Reproduction Number: 1.959503106
Herd Immunity Threshold: 0.48966654
Doses Required: 161320641.6
Program:
# Obtaining required input information population_size = int(input("Enter population size: ")) life_expectancy = float(input("Enter life expectancy: ")) file_name = input("Enter sample file name: ") # opening file with given filename f = open(file_name) # extracting file contents in int type by splitting file data and mapping into int values_list = list(map(int, f.read().split('\n'))) # calculating average age of infection average_age = sum(values_list)/len(values_list) # Base reproduction number R0 = life_expectancy/average_age # herd immunity threshold Q = 1 - (1/R0) # estimate number of doses e_num_doses = Q * population_size # printing each calculation result using labels given in sample output print("Average Age of Infection: ", average_age) # rounding values accordingly to match with given sample output while printing # these value rounding can be adjusted easily according to need print("Base Reproduction Number: ", round(R0, 9)) print("Herd Immunity Threshold: ", round(Q, 8)) print("Doses Required: ", round(e_num_doses, 1))
Program Snippet:
corona.txt:
Output Snippet:
I hope you got the provided solution.
Thank You.