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

03.PB Python Conditional Statements Advanced

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

03.PB Python Conditional Statements Advanced

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

Lab: Conditional Statements Advanced

Problems for lab exercise for the "Programming Basics" course @ SoftUni Global
Submit your solutions in the SoftUni Judge system at: https://judge.softuni.org/Contests/4581

1. Day of Week
Write a program that reads an integer entered by the user and prints a day of the week within [1 ... 7] or prints
"Error" if the number entered is invalid.

Sample Input and Output


Input Output
1 Monday
2 Tuesday
3 Wednesday
4 Thursday
5 Friday
6 Saturday
7 Sunday
-1 Error

Testing in the Judge System


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

2. Weekend or Working Day


Write a program that reads the day of the week (string) - entered by the user. If the day is a working day, it prints on
the console - "Working day", if it is a day off - "Weekend". If any text other than the day of the week is entered,
print "Error".

Sample Input and Output


Input Output
Monday Working day

Input Output
Sunday Weekend

Input Output
April Error

Testing in the Judge System


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

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

Follow us: Page 1 of 7


3. Animal Type
Write a program that prints the species of the animal according to its name entered by the user.
1. dog -> mammal
2. crocodile, tortoise, snake -> reptile
3. others -> unknown

Sample Input and Output


Input Output
dog mammal
snake reptile
cat unknown

Testing in the Judge System


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

4. Personal Titles
Write a console program that reads the age (a floating-point number) and gender ("m" or "f") entered by the user
and prints an address from the following:
 "Mr." - a man (gender "m") of 16 years or more
 "Master" - a boy (gender "m") under 16 years old
 "Ms." – a woman (gender "f") of 16 years or more
 "Miss" – a girl (gender "f") under 16 years old

Sample Input and Output


Input Output Input Output Input Output Input Output

12 17 25 13.5
Miss Mr. Ms. Master
f m f m

Hints and Guidelines


1. Create variables for age and gender and read their input from the console:

2. Checks the gender and then the age. In the body of the if-condition for age print the appropriate output:

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

Follow us: Page 2 of 7


3. Start the program with [Ctrl + Shift + F10] and test it with different input values

Testing in the Judge System


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

5. Small Shop
1. An enterprising person opens neighbourhood shops in several cities and sells at different prices:
city / product coffee water beer sweets peanuts
London 0.50 0.80 1.20 1.45 1.60
Rome 0.40 0.70 1.15 1.30 1.50
Paris 0.45 0.70 1.10 1.35 1.55
2. Write a program that reads product (string), city (string), and quantity (a floating-point number) entered by
the user and calculates and prints how much the corresponding quantity of the selected product costs in the
specified city.

Sample Input and Output


Input Output Input Output Input Output Input Output Input Output

coffee peanuts beer water sweets


Paris 0.9 Rome 1.5 London 3.6 Rome 1.4 London 3.2335
2 1 3 2 2.23

Hints and Guidelines


1. Create a new file in the PyCharm project;
2. Read the input data from the console and create the variable price, by assigning it the value of 0:

3. Make a series of conditions, where in each town you check the product. In each product check, change the
value of the price variable and then print it. Take a look at the example below:

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

Follow us: Page 3 of 7


Testing in the Judge System
Test your solution in the online Judge system https://judge.softuni.org/Contests/Compete/Index/4581#4

6. Number in Range
Write a program that checks if the number entered by the user is in the range [-100, 100] and is different from 0 and
print "Yes" if it meets the conditions, or "No" if it is outside the range.

Sample Input and Output


Input Output Input Output Input Output
-25 Yes 0 No 25 Yes

Hints and Guidelines


1. Read the integer from the console
2. Check whether it is in the interval [-100, 100] and is different from 0, if the condition results in"True", print
"Yes", otherwise print "No".

Testing in the Judge System


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

7. Working Hours
Write a program that reads an hour of the day (integer) and a day of the week (string) - entered by the user and
checks whether the company's office is open, the office hours are from 10:00(10 am) to 18:00(6 pm), from Monday
to Saturday including.

Sample Input and Output


Input Output Input Output Input Output
11 19 11
open closed closed
Monday Friday Sunday

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

Follow us: Page 4 of 7


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

8. Cinema Ticket
Write a program that reads the day of the week (string) - entered by the user and prints on the console the price of
a movie ticket according to the day of the week:

Sample Input and Output


Monday Tuesday Wednesda Thursday Friday Saturday Sunday
y
12 12 14 14 12 16 16

Testing in the Judge System


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

9. Fruit or Vegetable
Write a program that reads a product name entered by the user and checks if it is a fruit or vegetable.
 The fruits are banana, apple, kiwi, cherry, lemon, and grapes
 The vegetables "vegetable" are tomato, cucumber, pepper, and carrot
 Everything else is "unknown"
Print "fruit", "vegetable" or "unknown" depending on the introduced product.

Sample Input and Output


Input Output Input Output Input Output Input Output

banana fruit apple fruit tomato vegetable water unknown

Testing in the Judge System


Test the solution in the online Judge system: https://judge.softuni.org/Contests/Compete/Index/4581#8

10. Invalid Number


A number is valid if it is in the range [100… 200] or is 0. Write a program that reads an integer entered by the user
and prints "invalid" if the number entered is not valid.

Sample Input and Output


Input Output Input Output Input Output Input Output

75 invalid 150 (no output) 220 invalid 199 (no output)

Input Output Input Output Input Output Input Output

-1 invalid 100 (no output) 200 (no output) 0 (no output)

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

Follow us: Page 5 of 7


Testing in the Judge System
Test your solution in the online Judge system https://judge.softuni.org/Contests/Compete/Index/4581#9

11. Fruit Shop


Fruit shop on weekdays works at the following prices:
fruit banana apple orange grapefruit kiwi pineapple grapes
price 2.50 1.20 0.85 1.45 2.70 5.50 3.85
On Saturdays and Sundays, the store is works at higher prices:
fruit banana apple orange grapefruit kiwi pineapple grapes
price 2.70 1.25 0.90 1.60 3.00 5.60 4.20
Write a program that reads from the console fruit (banana / apple / orange / grapefruit / kiwi /
pineapple / grapes), day of the week (Monday / Tuesday / Wednesday / Thursday / Friday /
Saturday / Sunday), and quantity (a floating-point number), entered from the customer, and calculates the sum
according to the prices in the tables above. In case of an invalid day of the week or invalid fruit name, print "error".

Sample Input and Output


Outpu
Input Output Input Output Input Output Input Input Output
t

apple orange kiwi grapes tomato


Tuesday 2.40 Sunday 2.70 Monday 6.75 Saturday 2.10 Monday error
2 3 2.5 0.5 0.5

Testing in the Judge System


Test the solution in the online Judge system: https://judge.softuni.org/Contests/Compete/Index/4581#10

12. Trade Commissions


The company gives the following commissions to its merchants according to the city in which they operate and the
volume of sales:
City 0 ≤ s ≤ 500 500 < s ≤ 1 000 1 000 < s ≤ 10 000 s > 10 000
London 5% 7% 8% 12%
Paris 4.5% 7.5% 10% 13%
Rome 5.5% 8% 12% 14.5%
Write a console program that reads the city name (string) and sales volume (a floating-point number) entered by
the user and calculates the percentage of the trade commission according to the table above. Display the result
formatted to 2 digits after the decimal point. In case of invalid city or sales volume (negative number) print "error".

Sample Input and Output


Input Output Input Output Input Output Input Output

Londo InvalidName
Rome Paris
n 120.00 27.50 387.45 error
499.99 3874.50 -50
1500

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

Follow us: Page 6 of 7


Testing in the Judge System
Test the solution in the online Judge system: https://judge.softuni.org/Contests/Compete/Index/4581#11

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

Follow us: Page 7 of 7

You might also like