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.