Max. 9 points
Download hw_3.tar.gz and extract it. This archive contains a grader which works for all current versions of Python 3 and expects the solution files to be placed in the same directory. It has to be executed from this directory via
Add your solutions in the directory contained in the archive. Right after the shebang, each of your files must contain your name using the following template
.. moduleauthor:: Your Name <firstname.lastname@example.org>
We did not discuss every detail required to solve the following tasks. Use your favorite search engine and some common sense to solve the tasks.
This homework is to be prepared in teams of two students. Ask the lecturer to announce the teams to know who you'll be working with.
quadratic(a, b, c)that solves quadratic equations. If you have trouble solving this task, have a look at the Python functions video tutorial on youtube. In addition to what is shown in the video, the function must be able to deal with input leading to complex numbers as results.
sum_to(num)that takes an integer
num >= 0as sole argument. The function should return the sum of all positive integers
<= num. In the function, assert that the input is ≥ 0 by using
celsius2fahrenheit(.)that converts from Celsius to Fahrenheit and
fahrenheit2celsius(.)for the other way around.
Name the program file: geometry.py
terminal_value(capital, rate, years=1, tax=0). If a positive tax value is entered, every year's interest is to be reduced by the tax. The
taxparameters must be between 0 (0%) and 1 (100%). The number of years is integral. Use the formulas
interest(capital, rate, years=1, tax=0)that returns the profit (compound interest) of investing money.
encode(.)that takes a string and returns the given string rotated by 13 places. For symmetry, also provide a corresponding
decode(.)function. Convert the input to upper case before performing the rotation.
read_string_list(.)that opens a VRPTW data file given as filename argument. The argument must be optional and default to "r101"). If the argument doesn't contain a filename extension (".txt"), this extension must be added before opening the file. Your function should return a list of strings - one for each entry. The headers should not be included in that list.
Name the program file: vrptw_reader.py
[' 1 35.00 35.00 0.00 0.00 230.00 0.00\n',
' 2 41.00 49.00 10.00 161.00 171.00 10.00\n',
'100 20.00 26.00 9.00 83.00 93.00 10.00\n',
'101 18.00 18.00 17.00 185.00 195.00 10.00\n']
get_demand(.)takes two arguments. The first argument should be a list of strings (one for each entry) and the second should be a customer number (CUST_NO.). The function has to return that customer's demand as floating point number. The last function,
calc_distance(.), should take three parameters – a list of strings and two customer numbers. It should return the euclidean distance between the two customers.
The main function must be called itself using the ifmain pattern. If all went well, the main function must return 0 to inform the calling process of the successful termination. Name the program file: main.py
print('prime_addition.prime_sum_to(9); expected: 17, actual:',
All resulting files must be placed in a single directory. The name of the directory must be 3_firstname_lastname (in case of team homeworks, add each member's first and last names). Make sure to also include the grader. Compress the directory to either 3_firstname_lastname.tar.gz or 3_firstname_lastname.tar.bz2 before sending it to email@example.com.