Institute of Computer Science
  1. Courses
  2. 2020/21 fall
  3. Introduction to Programming II (MTAT.03.256)
ET
Log in

Introduction to Programming II 2020/21 fall

  • Home
  • Grading
  • Links

Homework 2

The deadline is Sunday, the 22nd of November, 23:59 (Estonian time).

Exercise 1. Birthdays

The birthdays in the file are written in the format dd.mm.yyyy (see an example). Write a program that reads the data from the file and creates a dictionary. The keys of the dictionary are the names of the months, and the values of the dictionary are the number of birthdays in each month. Print the dictionary out. Also, the program should have a function month_name that takes the number of a month as its argument and returns the name of the month (the function should not contain if-statements).

If the file dates.txt contains the following lines:

 11.10.2013
 07.08.2000
 23.05.2014
 31.10.2013
 02.02.1992

then the output of the program can be

 {'October': 2, 'August': 1, 'May': 1, 'February': 1}

Exercise 2. Phone book

When a person buys a new phone, there is only one phone number in the phone book (Emergency number - 112). Write a program that helps the person add phone numbers into the phone book. The program should repeatedly ask the user for a new contact name. If there is no such name in the phone book yet, the program should ask the user for the phone number. When the user is asked for a new contact name and the user enters done, the program outputs the total number of contacts in the phone book and all the records from the phone book.

Here is an example of the program output:

 Enter a name (done to quit): Emergency number
 Emergency number's phone number is 112
 Enter a name (done to quit): Andrew Parson
 There is no information for Andrew Parson
 What is Andrew Parson's number? 8806336
 Enter a name (done to quit): Emily Everett
 There is no information for Emily Everett
 What is Emily Everett's number? 6784346
 Enter a name (done to quit): Peter Power
 There is no information for Peter Power
 What is Peter Power's number? 7658344
 Enter a name (done to quit): Emily Everett
 Emily Everett's phone number is 6784346
 Enter a name (done to quit): done
 The phone book has 4 entries in it
 All records in the phone book: {'Emergency number': 112, 'Andrew Parson': '8806336', 'Emily Everett': '6784346', 'Peter Power': '7658344'}

Go to Moodle and upload your solution into Homework 2.

  • 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