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

Introduction to Programming 2020/21 fall

  • Home
  • Grading
  • Links

Homework 4

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

Exercise 1. Part of the multiplication table

Write a program which prompts the user for one integer. The program then multiplies the entered number by the numbers from 1 to 9. The result of the calculations has to be printed out in the way shown below.

Run the program repeatedly to test it on different input values.

Here are some examples of the program output.

 Please enter a number: 3
 3 * 1 = 3
 3 * 2 = 6
 3 * 3 = 9
 3 * 4 = 12
 3 * 5 = 15
 3 * 6 = 18
 3 * 7 = 21
 3 * 8 = 24
 3 * 9 = 27


 Please enter a number: 9
 9 * 1 = 9
 9 * 2 = 18
 9 * 3 = 27
 9 * 4 = 36
 9 * 5 = 45
 9 * 6 = 54
 9 * 7 = 63
 9 * 8 = 72
 9 * 9 = 81

Exercise 2. Number of days in months

Upgrade the number of days in months program : add a loop which repeatedly asks the user for the numbers of months and outputs the number of days in that month until the user enters “done”. The program does not have to perform the check for a leap year (let's say that the number of days in February is always 28). If the user enters something else but a number, the program processes the error using try and except, prints out an error message and asks for another number.

Here is an example of the program output.

 Enter the number of a month or word 'done': 3
 That month has 31 days in it
 Enter the number of a month or word 'done': 4
 That month has 30 days in it
 Enter the number of a month or word 'done': blabla
 Please enter a number
 Enter the number of a month or word 'done': -1
 The number of a month must be in the range 1-12
 Enter the number of a month or word 'done': 100
 The number of a month must be in the range 1-12
 Enter the number of a month or word 'done': 10
 That month has 31 days in it
 Enter the number of a month or word 'done': done

Go to Moodle and upload your solution into Homework 4.

  • 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