Homework 2
The deadline is Friday, the 19th of November, 19:00 (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.