0% found this document useful (0 votes)
9 views4 pages

04 Functions Lab

The document outlines a lab assignment consisting of seven programming tasks that require the implementation of various functions in Python. Tasks include calculating absolute values, converting grades to words, performing arithmetic operations, repeating strings, calculating order prices, computing rectangle areas, and rounding numbers. Each task provides input-output examples and hints for implementation.

Uploaded by

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

04 Functions Lab

The document outlines a lab assignment consisting of seven programming tasks that require the implementation of various functions in Python. Tasks include calculating absolute values, converting grades to words, performing arithmetic operations, repeating strings, calculating order prices, computing rectangle areas, and rounding numbers. Each task provides input-output examples and hints for implementation.

Uploaded by

fetata89
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Lab: Functions

Please, submit your source code solutions for the described problems to the Judge System.

1. Absolute Values
Write a program that receives a sequence of numbers, separated by a single space, and prints their absolute value
as a list. Use abs().

Example
Input Output

1 2.5 -3 -4.5 [1.0, 2.5, 3.0, 4.5]

-0 1 10 -6.66 [0.0, 1.0, 10.0, 6.66]

2. Grades
Write a function that receives a grade between 2.00 and 6.00 and print the corresponding grade in words.
 2.00 – 2.99 - "Fail"
 3.00 – 3.49 - "Poor"
 3.50 – 4.49 - "Good"
 4.50 – 5.49 - "Very Good"
 5.50 – 6.00 - "Excellent"

Examples
Input Output
3.33 Poor
4.50 Very Good
2.99 Fail

Hints
 Read the grade from the console:

 Then, create a function and make an if statement for each case:

© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 1 of 4


 Pass the input grade to the function:

3. Calculations
Create a function that receives three parameters, calculates a result depending on the given operator, and returns
it. Print the result of the function.
The input comes as three parameters – an operator as a string and two integer numbers. The operator can be one
of the following: "multiply", "divide", "add", and "subtract".

Example
Input Output
subtract 1
5
4
НЕ 2

Hints
 Read the input data from the console:

 Then, create the function and make an if statement for each case:

 Print the result by calling the function and passing the given parameters.

4. Repeat String
Write a function that receives a string and a counter n. The function should return a new string – the result of
repeating the old string n times. Print the result of the function. Try using lambda.

Examples
Input Output

© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 2 of 4


abc abcabcabc
3
String StringStrin
2 g

Hints
1. Read the input data:

2. Create the function:

3. Print the result:

5. Orders
Write a function that calculates the total price of an order and returns it. The function should receive one of the
following products: "coffee", "coke", "water", or "snacks", and a quantity of the product. The prices for a
single piece of each product are:

 coffee - 1.50
 water - 1.00
 coke - 1.40
 snacks - 2.00

Print the result formatted to the second decimal place.

Example
Input Output
water 5.00
5
coffe 3.00
e
2

6. Calculate Rectangle Area


Create a function that calculates and returns the area of a rectangle by a given width and height. Print the result on
the console.

Examples
Input Output
3 12
4

© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 3 of 4


6 12
2

7. Rounding
Write a program that rounds all the given numbers, separated by a single space, and prints the result as a list. Use
round().

Example
Input Output

1.0 2.5 3.0 4.5 [1, 2, 3, 4]

2.56 1.9 -3.4 8.1 [3, 2, -3, 8]

© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 4 of 4

You might also like