Question

In: Computer Science

DIRECTIONS: Complete the following Programming Exercise in Python. Name the file Lastname_Firstname_E1. You just started your...

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

Solutions

Expert Solution

  • Complete program is well commented for better understanding.
  • Program follows all the instructions given in question.
  • Snippets of program and corona.txt file are provided below the typed code.
  • Output snippet is also attached below.

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.


Related Solutions

Use Python to Complete the following on a single text file and submit your code and...
Use Python to Complete the following on a single text file and submit your code and your output as separate documents. For each problem create the necessary list objects and write code to perform the following examples: Sum all the items in a list. Multiply all the items in a list. Get the largest number from a list. Get the smallest number from a list. Remove duplicates from a list. Check a list is empty or not. Clone or copy...
Using the Prelude to Programming book, complete Programming Challenge 2 on page 463. Save your file...
Using the Prelude to Programming book, complete Programming Challenge 2 on page 463. Save your file as LASTNAME_FIRSTNAME_M07HW2. (worth 15 points) Create a program that allows the user to input a list of first names into one array and last names into a parallel array. Input should be terminated when the user enters a sentinel character. The output should be a list of email addresses where the address is of the following form: [email protected]. please help!!!!
Name your file “DMx1_Your last name_Your first name.” You can use MS Word to complete the...
Name your file “DMx1_Your last name_Your first name.” You can use MS Word to complete the matrices (go to Insert, Table, Insert table, fill the table). Save the file as a PDF file. If you draw the matrices on paper, take pictures. Make sure the pictures are clear and readable. Insert the pictures in MS Word document and save it as a PDF file. 1. Align using dot matrix: horizontal sequence – AGGCTCCC, vertical sequence – GCGCTCCG. Trace and explain...
Using Python You just started your summer internship with NU Bank as part of its growing...
Using Python You just started your summer internship with NU Bank as part of its growing development team. Your first assignment is to design and build two classes that are to be utilized in both the banks website and internal applications. The first is a loan class representing a loan contract. The second is a customer class representing the individual receiving the loan. You will be building the business logic classes, so you don’t have to worry about forms for...
Name your program file warmup.py Submit your working Python code to your CodePost.io account. In this...
Name your program file warmup.py Submit your working Python code to your CodePost.io account. In this challenge, establish if a given integer num is a Curzon number. If 1 plus 2 elevated to num is exactly divisible by 1 plus 2 multiplied by num, then num is a Curzon number. Given a non-negative integer num, implement a function that returns True if num is a Curzon number, or False otherwise. Examples is_curzon(5) ➞ True 2 ** 5 + 1 =...
Write a python program that does the following: Prompt for a file name of text words....
Write a python program that does the following: Prompt for a file name of text words. Words can be on many lines with multiple words per line. Read the file and convert the words to a list. Call a function you created called list_to_once_words(), that takes a list as an argument and returns a list that contains only words that occurred once in the file. Print the results of the function with an appropriate description. Think about everything you must...
Your primary task for this exercise is to complete header file by writing three functions with...
Your primary task for this exercise is to complete header file by writing three functions with its description below: removeAt function – to remove the item from the list at the position specified by location. Because the list elements are in no particular order (unsorted list), you could simple remove the element by swapping the last element of the list with the item to be removed and reducing the length of the list. insertAt function - to insert an item...
This is an exercise to design and write a Python program in good programming style for...
This is an exercise to design and write a Python program in good programming style for a simulation of stock price over a period of 100 days. In this exercise, you are asked to simulate the stock price starting at $100.00 for 100 days with a daily fluctuation based on the Normal Distribution with mean = 0.0 & sigma = 0.0125. The program will show the daily stock price, the 7-day minimum, the 7-day maximum, the 7-day average, and the...
PYTHON Exercise: Accelerate Method ------------------------- ### Description In this exercise, you will add to your `Car`...
PYTHON Exercise: Accelerate Method ------------------------- ### Description In this exercise, you will add to your `Car` class a method to accelerate the speed of an instance. ### Class Name `Car` ### Method `accelerate()` ### Parameters * `self` : the `Car` object to use * `delta_speed` : a number, the desired value to add to the speed data member. ### Action Adds `delta_speed` to the speed of the object. If the new speed is too fast, then set the speed to...
Complete the following assignment in C programming language. Get the user’s first name and store it...
Complete the following assignment in C programming language. Get the user’s first name and store it to a char array Declare a character array to hold at least 20 characters. Ask for the user’s first name and store the name into your char array. Hint: Use %s for scanf. %s will only scan one word and cannot scan a name with spaces. Get 3 exam scores from the user: Declare an array of 3 integers Assume the scores are out...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT