Practice 5: Computer Science (Code 30424) A.Y. 2018-2019
Practice 5: Computer Science (Code 30424) A.Y. 2018-2019
2018-2019
Practice 5
You are asked to answer the following questions and solve the following problems:
The file to work on is called Coins.py and contains part of a program written in Python for the
simulation of a coin toss with the aim of verifying empirically that by throwing a coin (not
rigged) you have an equal chance of getting heads or tails, that is 50% of throws will be heads
and 50% of throws will be tails.
You are asked to write the code necessary to complete the program so that:
• it simulates the toss of the coin for the number of times entered by the user and that the
outcome of the tosses is stored in the heads or tails variables. Note: it is advisable to use
the randint function of the random module;
• it asks the user if he wants to see the result in percentage. Make sure that different
affirmative answers are valid (for example YES, yes etc.);
• it shows the following message on the screen with the result of the simulation (on two
lines):
Heads tosses = XX
Tails tosses = XX
Depending on the user's choice, the number of tosses must be shown as an integer
number or as a number with decimals.
Create a new Python file called divisors.py that calculates all the divisors of a number entered
by the user. In particular, the program must:
• ask the user for an integer greater than 1;
• calculate and show on screen all the divisors of the entered number (excluded);
• show on screen the number of divisors found at the end of the operation.
1
3) Creation of a program that calculates the taxes on income to be paid
Create a new Python file called taxes.py which, based on the user's annual income, calculates
the taxes to be payed and asks how much he/she wants to save after paying the taxes. In
particular, the program must:
• ask the user his/her annual income (allowing to enter also numbers with decimals);
• calculate the taxes to be paid based on the following table
• show a message on screen stating the amount of taxes to be paid (in euros) and the
income available after paying the taxes, both with two decimals;
• ask the user how much he/she wants to save of the income available after paying the
taxes (allow to enter also numbers with decimals). Make sure that this number cannot
exceed 50% of income available. If not, ask the user to enter again how much he/she
wants to save until the entered number is correct.
Create a new Python file called range.py that shows on screen all the numbers between two
numbers, excluding the multiples of 3 and 5. In particular, the program must:
• ask the user two integer numbers, one between 0 and 10 (both included) and the other
greater than 10;
• make sure that if the entered numbers do not meet the requirements, the user is asked
again to enter the numbers until they are both correct;
• show on screen all the numbers between the first and the second entered number (both
included), except the multiples of 3 and the multiples of 5.