Institute of Computer Science
  1. Courses
  2. 2021/22 fall
  3. Introduction to Programming (MTAT.03.236)
ET
Log in

Introduction to Programming 2021/22 fall

  • Home
  • Grading
  • Links

Homework 7

The deadline is Sunday, the 24th of October, 23:59 (Estonian time).

NB! Make sure that the text files (.txt) are in the same folder as your Python code. Otherwise Python will not find the file.

Exercise 1. Celsius and Fahrenheit

Create the text file temps.txt. In the file, write temperatures in Celsius (each value on a separate line). Create a program which reads temperatures from a file (that contains temperatures in Celcius), converts the temperatures to Fahrenheit and stores the converted temperatures into a list (Hint: you can use the function we wrote in one practice session to convert from Celcius to Fahrenheit). The program should print out the average, maximum and minimum of the Fahrenheit temperatures.

Exercise 2. Number of days in months

Rewrite the number of days in months program so that the program prompts the user for the file name and reads the dates from the file. The dates in the file are written in the format dd.mm.yyyy (see an example). The program looks for the month in each line (hint: use split) and prints out the number of days in that month. Rewrite the function so that it does not contain conditional (if) statements for returning the number of days. The function should do it using a list (look at example code 2). Do not add the check for a leap year (let’s say that there are 28 days in February).

Go to Moodle and upload your solution into Homework 7.

  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment