Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
76 views

02.PB Python Conditional Statements Exercise

The document provides sample problems and instructions for conditional statements exercises. It includes problems about calculating total time from seconds entered, calculating bonus points based on starting points, and calculating time after a certain number of minutes. It also provides two sample exam problems about calculating profits from a toy shop order and whether funds are enough for a film shoot based on extras, clothing, and decor.

Uploaded by

Milica Janković
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views

02.PB Python Conditional Statements Exercise

The document provides sample problems and instructions for conditional statements exercises. It includes problems about calculating total time from seconds entered, calculating bonus points based on starting points, and calculating time after a certain number of minutes. It also provides two sample exam problems about calculating profits from a toy shop order and whether funds are enough for a film shoot based on extras, clothing, and decor.

Uploaded by

Milica Janković
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Exercise: Conditional Statements

Problems for exercise and homework for the "Programming Basics" course @ SoftUni Global
Submit your solutions to the SoftUni Judge system at: https://judge.softuni.org/Contests/4580

1. Sum Seconds
Three athletes finish in a matter of seconds (between 1 and 50). Write a program that reads the times of the
competitors in seconds entered by the user and calculates their total time in the format "minutes:seconds". Display
the seconds with leading zero (2  "02", 7  "07", 35  "35").

input output input output input output input output


35 2:04 22 1:03 50 2:29 14 0:36
45 7 50 12
44 34 49 10

Hints and Guidelines:


1. Read the input data (competitors' seconds):

2. Create a new variable to store the sum of the seconds of the three competitors:

3. Once you have found the sum of the seconds, you need to convert them to minutes and seconds (for
example, if the sum is 85 seconds, this is 1 minute and 25 seconds, because 1 minute has 60 seconds).
Create two new variables. In the first variable, calculate how many minutes the sum of seconds is by
dividing the sum by 60. In the second variable, calculate the seconds using division by the remainder (%).
Use division with remainder (%) to take the remainder when dividing by 60, which is the remaining seconds.
For example, you have a total of 134 seconds (2 minutes and 14 seconds) after the integer division (/) of 60
we get 2 and the remainder 14, which we take with the division by the remainder (%).

Round the result minutes to the lower number, to remove the floating-point part.
4. Once you know how many minutes and seconds is the total, we need to print them in the correct format
(minutes:seconds) If the seconds are less than 10, print 0 before the number

Testing in the Judge System


Test your solutions in the online Judge system https://judge.softuni.org/Contests/Compete/Index/4580#0

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 1 of 8


2. Bonus Score
An integer is given - the starting number of points. Bonus points are added to it according to the rules described
below. Write a program that calculates the bonus points received by the number and the total number of points
(number + bonus).
 If the number is up to 100 inclusive, the bonus points are 5.
 If the number is greater than 100, the bonus points are 20% of the number.
 If the number is greater than 1000, the bonus points are 10% of the number.

 Additional bonus points (added separately from the previous ones):


o For an even number  + 1 point.
o For a number ending in 5  + 2 points.

Sample Input and Output


Input Output Input Output Input Output Input Output
20 6.0 175 37.0 2703 270.3 15875 1589.5
26.0 212.0 2973.3 17464.5

Hints and Guidelines:


1. Read the input date (an integer):

2. Create a new variable of type double, in which you will calculate the accumulated bonus points, giving it a
starting value of 0.

3. Make an if-else-if construction for three conditions to check the size of the number and calculate the
bonus.

4. Create a new if-else-if construct to perform the conditions and calculate the additional bonus. If the
number is even, add 1 to the bonus accumulated so far, and if it ends at 5, add 2 to the bonus. To check if a
number is even, you must divide it by 2, and if you get a remainder divided by 0, then the number is even.
but if you get a remainder of 1, it means that the number is odd. For example, the number 34 is even
because 34/2 = 17 and the remainder is 0, and the number 35 is odd because 35/2 = 17 with a remainder of
1. To check if a number ends in 5 you have to divide the number by 10 and if get a remainder in division 5,
so the number ends in 5. For example, the number 245/10 = 24 with the remainder 5.

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 2 of 8


5. Print the results in two lines. On the first row is the accumulated bonus and on the second is the final
number, which you will find by adding the initial number of points and the bonus.

Testing in the Judge System


Test your solutions in the online Judge system https://judge.softuni.org/Contests/Compete/Index/4580#1

3. Time + 15 Minutes
Write a program that reads the hour and minutes of the 24-hour day entered by the user and calculates what time it
will be in 15 minutes. Print the result in hours:minutes. The hours are always between 0 and 23, and the minutes
are always between 0 and 59. The hours are written in one or two digits. Minutes are always displayed in two digits,
with a leading zero when necessary.

Sample Input and Output


Input Output Input Output Input Output Input Output Input Output
1 2:01 0 0:16 23 0:14 11 11:23 12 13:04
46 01 59 08 49

Testing in the Judge System


Test your solutions in the online Judge system https://judge.softuni.org/Contests/Compete/Index/4580#2

Sample Exam Problems


4. Toy Shop
Sophie has a toy store. She receives a large order that she must fulfill. With the money she will earn, she wants to go
on a trip.
Toy prices:
 Puzzle - 2.60 USD.
 Talking doll - 3 USD.
 Teddy bear - 4.10 USD.
 Minion - 8.20 USD.
 Truck - 2 USD.
If the ordered toys are 50 or more, the store makes a 25% discount on the total price. Sophie must give 10% of the
earned money for the rent of the store. Calculate whether the money will be enough for her to go on a trip.

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 3 of 8


Input Data
6 lines are read from the console:
1. Price of the trip – floating-point in the interval [1.00 … 10000.00]
2. Number of puzzles – integer in the interval [0… 1000]
3. Number of talking dolls - integer in the interval [0 … 1000]
4. Number of teddy bears - integer in the interval [0 … 1000]
5. Number of minions - integer in the interval [0 … 1000]
6. Number of trucks - integer in the interval [0 … 1000]

Output Data
On the console print:
 If the money is enough print:
o "Yes! { remaining money } USD left."
 If the money isn’t enough print:
o "Not enough money! { needed money } USD needed."

The result must be formatted to the second decimal symbol.

Sample Input and Output


Input Output Comments
40.8 Yes! 418.20 USD left. Sum: 20 * 2.60 + 25 * 3 + 30 * 4.10 + 50 * 8.20 + 10 * 2 = 680 USD
20 Number of toys: 20 + 25 + 30 + 50 + 10 = 135
25 135 > 50 => 25% discount; 25% from 680 = 170 USD discount
30 Final price: 680 – 170 = 510 USD
50 Rent: 10% from 510 USD = 51 USD
10 Profit: 510 – 51 = 459 USD
459 > 40.8 => 459 – 40.8 = 418.20 USD remain
Input Output
320 Not enough money! 238.73 USD Sum: 8 * 2.60 + 2 * 3 + 5 * 4.10 + 5 * 8.20 + 1 * 2 = 90.3 USD
8 needed. Number of toys: 8 + 2 + 5 + 5 + 1 = 21
2 21 < 50 => no discount
5 Rent: 10% from 90.3 = 9.03 USD
5 Profit: 90.3 – 9.03 = 81.27 USD
1 81.27 < 320 => 320 – 81.27 = 238.73 USD are not enough

Testing in the Judge System


Test your solutions in the online Judge system https://judge.softuni.org/Contests/Compete/Index/4580#3

5. Godzilla vs. Kong


Filming for the long-awaited film "Godzilla vs. Kong" begins. Screenwriter Adam Wingard asks you to write a
program to calculate whether the funds provided are enough to shoot the film. The photos will require a certain
number of extras, clothing for each extra, and decor.
It is known that:
 The set for the film is worth 10% of the budget.
 For more than 150 extras, there is a 10% discount on clothing.

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 4 of 8


Input Data
3 lines are read from the console:
 Movie Budget- a floating-point number in the interval [1.00… 1000000.00]
 Number of extras - an inter in the range [1…500]
 Price for clothing of one extra – floating-point in the interval [1.00… 1000.00]

Output Data
Two rows are printed on the console:
 If the money for decor and clothes is more than the budget:
o "Not enough money!"
o "Wingard needs {needed money for the movie} USD more."
 If the money for decor and clothes is less than or equal to the budget:
o "Action!"
o "Wingard starts filming with {money left} USD left."
The result must be formatted to the second decimal symbol.

Sample Input and Output


Input Output Comments
20000 Action! Sum for decor: 10% from 20000 = 2000 USD
120 Wingard starts filming with Sum for clothes: 120 * 55.5 = 6660 USD
55.5 11340.00 USD left.
Total sum for the movie: 2000 + 6660 = 8660 USD
20000 – 8660 = 11340 USD remaining
15437.62 Action! Sum for decor: 10% from 15437.62 = 1543.762 USD
186 Wingard starts filming with Sum for clothes: 186 * 57.99 = 10786.14 USD
57.99 4186.33 USD left.
Extras are more than 150, therefore, there is a 10%
discount on clothes
10% from 10786.14 is 1078.614
10786.14 – 1078.614 = 9707.526 USD for clothes
Total sum for the movie: 1543.762 + 9707.526 =
11251.288 USD
15437.62 – 11251.288 = 4186.331 USD left
9587.88 Not enough money! Sum for decor: 10% from 9587.88 = 958.788 USD
222 Wingard needs 2495.77 USD Sum for clothes: 11124.864 USD
55.68 more. Total sum for the movie: 958.788 + 11124.864 =
12083.652 USD
9587.88 – 12083.652 = 2495.77 USD needed

Testing in the Judge System


Test your solutions in the online Judge system https://judge.softuni.org/Contests/Compete/Index/4580#4

6. World Swimming Record


Oliver decides to break the World Record for long-distance swimming. On the console, we type: the record that
Oliver has to break, the distance in meters he has to swim, and the time in seconds for which he swims a distance
of 1 m. To write a program that calculates whether he has done the record, it must be considered that: the

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 5 of 8


resistance of the water slows him down every 15 m by 12.5 seconds. After calculating how many seconds Oliver
will slow down, the result should be rounded down to the nearest integer number.
Calculate the time in seconds for which Ivan will swim the distance and the difference from the World Record.

Input Data
3 lines are read from the console:
1. The records in seconds – a floating-point number in the interval [0.00 … 100000.00]
2. The distance in meters – a floating-point number in the interval [0.00 … 100000.00]
3. The time in seconds for which he swims 1 meter - a floating-point number in the interval [0.00 … 1000.00]

Output Data
Printing the console depends on the result:
 If Oliver has broken the World Record (his time is less than the record) we print:
o "Yes, he succeeded! The new world record is {time of Oliver} seconds."
 If he has NOT broken the record (his time is greater than or equal to the record) we print:
o "No, he failed! He was {needed seconds} seconds slower."
The result must be formatted to the second decimal symbol.

Sample Input and Output


Input Output Comments
10464 No, he failed! He was Oliver must swim 1500 meters: 1500 * 20 = 30000 seconds.
1500 20786.00 seconds slower. On each 15 meters, we add 12.5 seconds to his time:
20 1500 / 15 = 100 * 12.5 = 1250 seconds.
Total time: 30000 + 1250 = 31250 seconds.
10464 < 31250
The time he needed to break the world record:
31250 - 10464 = 20786 seconds.
Input Output
55555.67 Yes, he succeeded! The Oliver must swim 3017 meters: 3017 * 5.03 = 15175.51 seconds.
3017 new world record is On each 15 meters, we add 12.5 seconds to his time:
5.03 17688.01 seconds. 3017/ 15 = 201 * 12.5 = 2512.50 seconds.
Total time: 15175.51 + 2512.50 = 17688.01 seconds.
Record is beaten: 55555.67 > 17688.01

Testing in the Judge System


Test your solutions in the online Judge system https://judge.softuni.org/Contests/Compete/Index/4580#5

7. Shopping
Peter wants to buy N video cards, M CPUs, and P number of RAM. If the number of video cards is greater than that
of the processors, he receives a 15% discount on the final bill. The following prices apply:
 Video card - 250 USD for one.
 CPU - 35% from the total price of purchased video cards.
 RAM - 10% from the total price of purchased video cards.
Calculate the amount needed to purchase the materials and calculate whether the budget will be enough.

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 6 of 8


Input Data
4 lines are read from the console:
1. Peter’s budget – a floating-point number in the interval [0.0…100000.0]
2. Number of video cards – an integer in the interval [0…100]
3. Number of CPUs – an integer in the interval [0…100]
4. Number of RAM – an integer in the interval [0…100]
Output Data
On the console, print one row with the following text:
 If the budget is enough:
"You have {budget left} USD left!"
 If the budget is not enough:
"Not enough money! You need {needed sum} USD more!"
Format the result to the second decimal symbol.
Sample Input and Output
Input Output Comments
900 You have 198.75 USD left! Budget: 900 USD
2 Sum for the requested video cards: 2 * 250 = 500 USD
1
3 Sum for a single CPU: 35% from 500 = 175 USD
Sum for requested CPUs: 1 * 175 = 175 USD

Sum for a single RAM: 10% from 500 = 50 USD


Sum for requested RAMs: 3 * 50 = 150 USD

Total sum: 500 + 175 + 150 = 825 USD


The number of video cards is greater than the number
of CPUs, so he gets 15% discount from the final price:
825 – 15% = 701.25 USD
701.25 <= 900
=> the money is enough
=> money left: 900 – 701.25 = 198.75 USD
920.45 Not enough money! You need 3.92 USD Budget: 920.45 USD
3 more! Sum for the requested video cards: 3 * 250 = 750 USD
1
1 Sum for a single CPU: 35% from 750 = 262.50 USD
Sum for requested CPUs: 1 * 262.50 = 262.50 USD

Sum for a single RAM: 10% from 750 = 75 USD


Sum for requested RAMs: 1 * 75 = 75 USD

Total sum: 750 + 262.50 + 75 = 1087.50 USD


The number of video cards is greater than the number
of CPUs, so he gets 15% discount from the final price:
1087.50 – 15% = 924.37 USD
924.37 > 920.45
=> the money isn’t enough
=> money needed 924.375 - 920.45 = 3.92 USD

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 7 of 8


Testing in the Judge System
Test your solutions in the online Judge system https://judge.softuni.org/Contests/Compete/Index/4580#6

8. Lunch Break
During the lunch break, you want to watch an episode of your favorite series. Your task is to write a program that
will find out if you have enough time to watch the episode. During the holiday you spend time for lunch and time
for rest. Lunchtime will be 1/8 of the rest time, and rest time will be 1/4 of the rest time.

Input Data
3 lines are read from the console:
1. Name of the series - a string
2. Episode duration - an integer in the range [10… 90]
3. Duration of the break - an integer in the range [10… 120]

Output Data
On the console print:
 If you have enough time to watch the episode:
"You have enough time to watch {name of series} and left with {time left} minutes free
time."
 If you don’t have enough time:
"You don't have enough time to watch {name of series}, you need {needed time} more
minutes."
The time must be rounded to the nearest greater integer.

Sample Input and Output


Input Output Comments
Game of Thrones You have enough time to watch Time for lunch: 96 * 1/8 = 12.0
60 Game of Thrones and are left with Break time: 96 * 1/4 = 24.0
96 0 minutes of free time.
Remaining time: 96 - 12 - 24 = 60
The rest time is more or equal to the length
of the episode, and we print the
appropriate output.
Teen Wolf You don't have enough time to Time for lunch: 60 * 1/8 = 7.5
48 watch Teen Wolf, you need 11 more Break time: 60 * 1/4 = 15.0
60 minutes.
Remaining time: 60 – 7.5 - 15 = 37.5
The rest time is less than the length of the
episode, and we print the appropriate
output.

Testing in the Judge System


Test your solutions in the online Judge system https://judge.softuni.org/Contests/Compete/Index/4580#7

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 8 of 8

You might also like