02.PB Python Conditional Statements Exercise
02.PB Python Conditional Statements Exercise
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").
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
© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
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.
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.
© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
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."
© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
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.
© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
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.
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.
© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
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.
© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.