0% found this document useful (0 votes)
29 views2 pages

Practice 5: Computer Science (Code 30424) A.Y. 2018-2019

This document outlines four programming problems to solve in Python: 1) Completing a coin toss simulation program that tracks the number of heads and tails over a number of user-specified tosses and displays the results. 2) Creating a program that calculates all the divisors of a user-entered integer number. 3) Creating a program that calculates income taxes owed based on tax brackets and allows the user to specify savings amount. 4) Creating a program that displays numbers between two user-entered integers, excluding multiples of 3 and 5.

Uploaded by

ka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views2 pages

Practice 5: Computer Science (Code 30424) A.Y. 2018-2019

This document outlines four programming problems to solve in Python: 1) Completing a coin toss simulation program that tracks the number of heads and tails over a number of user-specified tosses and displays the results. 2) Creating a program that calculates all the divisors of a user-entered integer number. 3) Creating a program that calculates income taxes owed based on tax brackets and allows the user to specify savings amount. 4) Creating a program that displays numbers between two user-entered integers, excluding multiples of 3 and 5.

Uploaded by

ka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Computer science (code 30424) a.y.

2018-2019

Practice 5

You are asked to answer the following questions and solve the following problems:

1) Completion of a program for the simulation of a coin toss

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.

The program is incomplete and contains:

• the importing of the random module;


• two variables, heads and tails, initialized at 0, which will have to store the number of
tosses with heads or tails as a result;
• the request to the user to enter the number of coin tosses to be simulated.

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.

2) Creation of a program that calculates the divisors of a number

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

Income Taxes rates


0 – 10,000 euros 0%
10,001 – 29,000 euros 20%
29,001 – 65,000 euros 30%
65,001 – 110,000 euros 40%
110,001 or more 45%

• 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.

4) Creation of a program that shows on screen some numbers

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.

You might also like