Take-home final exam CS1026B
Released at noon on April 19, 2020. Due at hoon, April 21, 2020.
You are free to refer to books, lecture notes, Internet, etc. but it must be your individual effort. If you have clarification questions, please email charles.ling@uwo.ca and jzha337@uwo.ca, and we will answer them quickly (or send out an announcement).
You can submit your solutions as many times as you want via your OWL account, but only the last submission (before the deadline) counts. Not to cause confusion, you must submit solutions to all questions together in one submission. If you re-submit, some parts can be the same as your last submission and this is OK.
To make a submission, attach one or more Python files (.py), and at the end of the Python file, use comments to include the outputs/outcome of your codes. You can also include explanations of your codes or your outputs in comment. You don’t need to submit other files such as screenshots.
At the beginning of your Python files, put in your student number and name in comment.
Total marks: 100, to be scaled down to 13%. You can select any 4 questions out of 5, and each question is 25 marks. If you finish all 5 questions, we will select the 4 highest ones as your total mark.
Stay home and be healthy! Good Luck!
1. We are defining two functions, f and g on integers, as follows: For example:
a. Given an integer , write two functions to calculate the value of f(n) and g(n).
b. What are the values of and g(5)?
2. Regarding the coronavirus pandemic, we want to build a model to help decision makers in the government to make better decisions. Write a program with these parameters to anticipate how many people would have got the virus and would have died after d days, based on certain assumptions (parameters here).
Note that these parameters can be given as user input, parameters of functions, assigning values to variables, and so on in your Python program. You will need to run your Python program multiple times to model the future with reasonable parameter settings, and show the results.
f(0) = 0, for n > 0, f(n) = f(n-1) + 2 * g(n-1)
g(0) = 1, for n > 0, g(n) = 2* g(n-1) – 3 * f(n-1)
For n = 1,
f(1) = f(0)+2 * g(0) = 2, g(1) = 2 * g(0) – 3 * f(0) =2
For n = 2,
f(2) = f(1) + 2 * g(1) = 2 + 2 * 2 = 6, g(2) = 2 * g(1) – 3 * f(1) = 2 * 2 – 3 * 2 = -2
n (n>=0)
f(5)
The parameters are as follows:
N = Number of people who currently carry the coronavirus
X = Death rate (a small number, say 0.1%) of people would die if they have the virus each day.
M = The average number of (healthy) people who are in close contact with the people with coronavirus every day.
p = The chance (or probability) of close contacts getting coronavirus with a mask
q = The chance of close contacts getting coronavirus without a mask
r = Percentage of people wearing mask in in general
d = Number of days
Try several sets of parameters and print out the total number of people who would have the virus and would have died after d d ays for each case. Put one to two sentences to explain the outcome.
Note: You may make additional assumptions and explain them in the comment of your code.
3. Given a list of integers, define a function to find two elements from the list whose values add up to a required result. The parameters of this function will be a list of integers and a value for result, and you need to print a of these two elements.
For example:
Note: You only need to print one solution, if it exists. If there is no solution, print out a message to say so.
Test your codes on several sets of inputs, and show the outputs of your program.
4. Given a list of integers, write a function to find if there is one and only one duplicate of exactly two numbers. Your function will return “True” if one and only one value appears twice in the list. In other cases, it will return “False”.
For example:
5. Write a function to check if a password is secure. This function will take a password as input and print its safety level. The password should have at least 8 characters, and at most characters; otherwise, your function will print “Invalid Password”. If the password contains letter and at least one digit, and not contains three or more repeating characters in a row, this password will be considered as a “Strong Password”. For other passwords, your function will print “Weak Password”.
dictionary of the index and the value
Input: num_pool = [2, 7, 8, 12], result = 9
Output: {0:2, 1:7}
Since num_pool[0] + num_pool[1] = 2 + 7 = 9, your output will be {0:2, 1:7}, where 0 is the index
and 2 is the value, 1 is the index and 7 is the value, and 2 + 7 = 9 (the result)
Input:[1, 2, 3, 1] Output: True
Input:[1, 2, 2, 3, 4, 5] Output: True
Input: [1, 2, 3, 4, 5] Output: False
Input: [1, 2, 1, 1] Output: False
Input:[1, 2, 1, 2] Output: False
15
at least one
For example:
Input: 123abc Output: Invalid Password
Input: 123456789abcdefg Output: Invalid Password
Input: 12345AbcD Output: Strong Password
Input: 11213abcd Output: Strong Password
Input: 11145abcd Output: Weak Password
Input: 12aaaaabcd Output: Weak Password
Input: 1234567890 Output: Weak Password
Input: abCdefGhiJ Output: Weak Password