During session 3
Exercises
1. What is the name of the month?
Write a function called month_as_name that takes the number of the month as its parameter and returns the name of the corresponding month. You can reuse and modify your solution from last week.
Example of the function call:
>>> month_as_name(9) 'September'
Test your function on different inputs.
2. Date as string
Write a function called date_as_string which takes three parameters: day, month and year (all in numbers) and returns a string that represents the date in the form monthname day, year (for example September 10, 1991). Then write a program that asks the user to enter a day, a month and a year in numbers, and the program outputs the corresponding date as a string.
Hint: you can and should reuse the function from exercise 1.
Example of the function call:
>>> date_as_string(26,9,2018) 'September 26, 2018'
Example of the program output:
Enter a day: 24 Enter a number of month: 2 Enter a year: 1918 February 24, 1918
3. Money change
Write a function called money_change which takes an amount of money in English pounds as its parameter, converts it into euros and returns the result (currency exchange rate: 1 GBP = 1.12 EUR). Call this function at least twice in the program; at least one of the calls must be based on the data asked from the user). Output the results in euros.
Example of the function call:
>>> money_change(150.5) 168.56
Example of the program output:
Please enter an amount of money in English pounds: 100 This is 112.0 EUR 500 GBP is 560.0 EUR
4. Budget
The Brown's are organising a party. They have invited a large number of people. Some guests have already informed about their attendance; the others haven't yet. Apart from that the Brown's need to calculate the expenses. The party budget consists of the expenses on food (10 euros per person) and a room rent (a fixed price of 55 euros regardless of the number of people). Write a program which would help calculate the maximum or minimum amount of the expenses.
First, create a function called budget. The function takes the number of people as its parameter, calculates the budget based on the provided amount of people and returns the total amount of money spent on a party. (For example, if the argument is 5, the total amount of money spent on the party is 105).
Next, write a program which:
- prompts the user for the number of guests;
- prompts the user for the number of guests who have informed about their attendance;
- calculates and outputs the maximum amount of the expenses if everyone attends (invoke the function);
- calculates and outputs the minimum amount of the expenses if the ones, who have informed about their attendance, show up (invoke the function).
Example of function call:
>>> budget(8) 135
Example of program output:
Please enter the number of invited people: 26 Please enter the number of people attending: 15 Maximum budget: 315 EUR Minimum budget: 205 EUR