In this project, you will build a program to predict the new Covid-19 cases using the basic reproduction number (R0). R0 represents the average number of people who will catch the disease from one infected person. Your program will predict how the number of cases grows based on this factor. This project will enhance your understanding of lists, for loops, and functions in programming.
This project involves coding a simple Covid-19 prediction model based on R0, and submitting a video demonstrating how your program works. There is no report required for this project.
Platform: Any Python IDE (e.g., Google Colab, Jupyter Notebook, or local Python setup)
Requirements:
Basic Reproduction Number (R0): Understand and implement the basic reproduction number (R0) to predict how the disease spreads. The formula for predicting new cases is:
New Cases = Previous Cases x R0
Use of Lists: Use lists to track the number of cases for each day or iteration.
For Loops: Create a loop to predict new cases for a certain number of days, based on the R0 value.
Functions: Define a function to calculate and update the number of new cases based on R0, and another function to display the results for each day.
Output: Display the prediction for each day, showing how the number of new cases increases over time.
and make a copy of Colab Notebook into your Google Drive for coding.
To predict the Covid-19 cases in Malaysia, the basic reproduction number (R0) of Covid-19 in Malaysia is used. In short, the R0 is a projection of how many people on average each new Covid-19 patient would infect.
Example:
R0 for a husband to wife: 1.0
R0 for a husband to wife and 1 child: 2.0
Important facts:
The best R0 to control the number of cases is below 0.5.
We had only 45 new cases on 11 September 2021, but the R0 was 2.34.
Conditional Movement Control Order (CMCO) in Sabah, Selangor, Putrajaya and Kuala Lumpur has brought the R0 down to below 1.0
📝 Milestone Checkpoint 1
✅ Goal: Calculate the average R0 from historical data
⏱️ Time: ~1 hour
🎯 Success Criteria: Your program can calculate R0 from user-provided case data
⚠️ Important
Make sure your data_r0 list is not empty before calculating the average!
Define an average function to calculate the average of R0 as follows [Copy and paste]:
less
defaverage(data_r0):
a = 0forbindata_r0:
a += breturna / len(data_r0)
Call the average function with the list "data_r0" as the argument. Store the value returned by the average function in a variable named "r0" with 2 decimal places. [Hint: average()]
Print the results of data_cases, data_r0 and r0 as follows:
yaml
Howmanydaysofdatadoyouwanttoinsert?3Cases for 3 day(s) before:1095Cases for 2 day(s) before:2188Cases for 1 day(s) before:1500Data Cases: [1095, 2188, 1500]
Calculated r0: [2.0, 0.69]
Average of r0:1.34
Remarks: More days of data leads to more accurate prediction of R0.
Call the randomr0() function with the variable "r0" as the argument. Store the value returned by the randomr0 function in a variable named "new_r0" in 2 decimal places.
ini
new_r0 = round(randomr0(r0), 2)
Calculate new case by using the formula as follows:
new_case = yesterday_newcases * new_r0
css
new_case = int(predict["new_cases"][i] * new_r0)
Calculate cumulative case by using the formula as follows: