filmov
tv
module_2_lab_5 python 5th lab

Показать описание
LAB
Estimated time
20 minutes
Level of difficulty
Intermediate
Objectives
• becoming familiar with the concept of numbers, operators and arithmetic operations in Python;
• understanding the precedence and associativity of Python operators, as well as the proper use of parentheses.
Scenario
Your task is to complete the code in order to evaluate the following expression:
x = float(input("Enter value for x: "))
# put your code here
print("y =", y)
The result should be assigned to y. Be careful - watch the operators and keep their priorities in mind. Don't hesitate to use as many parentheses as you need.
You can use additional variables to shorten the expression (but it's not necessary). Test your code carefully.
Test Data
Sample input: 1
Expected output:
y = 0.6000000000000001
Sample input: 10
Expected output:
y = 0.09901951266867294
Sample input: 100
Expected output:
y = 0.009999000199950014
x = float(input("Enter value for x: "))
y= 1/(x+(1/(x+(1/(x+(1/x))))))
print("y =", y)
LAB
Estimated time
15-20 minutes
Level of difficulty
Easy
Objectives
• improving the ability to use numbers, operators, and arithmetic operations in Python;
• using the print() function's formatting capabilities;
• learning to express everyday-life phenomena in terms of programming language.
Scenario
Your task is to prepare a simple code able to evaluate the end time of a period of time, given as a number of minutes (it could be arbitrarily large). The start time is given as a pair of hours (0..23) and minutes (0..59). The result has to be printed to the console.
hour = int(input("Starting time (hours): "))
mins = int(input("Starting time (minutes): "))
dura = int(input("Event duration (minutes): "))
# put your code here
For example, if an event starts at 12:17 and lasts 59 minutes, it will end at 13:16.
Test Data
Sample input: 12 17 59
Expected output: 13:16
Sample input: 23 58 642
Expected output: 10:40
Sample input: 0 1 2939
Expected output: 1:0
121%60=1
34%24=10
hour = int(input("Starting time (hours): "))
mins = int(input("Starting time (minutes): "))
dura = int(input("Event duration (minutes): "))
total_time=hour*60
total_time=total_time + mins + dura
print((total_time//60)%24, end=":")
print(total_time%60)
Estimated time
20 minutes
Level of difficulty
Intermediate
Objectives
• becoming familiar with the concept of numbers, operators and arithmetic operations in Python;
• understanding the precedence and associativity of Python operators, as well as the proper use of parentheses.
Scenario
Your task is to complete the code in order to evaluate the following expression:
x = float(input("Enter value for x: "))
# put your code here
print("y =", y)
The result should be assigned to y. Be careful - watch the operators and keep their priorities in mind. Don't hesitate to use as many parentheses as you need.
You can use additional variables to shorten the expression (but it's not necessary). Test your code carefully.
Test Data
Sample input: 1
Expected output:
y = 0.6000000000000001
Sample input: 10
Expected output:
y = 0.09901951266867294
Sample input: 100
Expected output:
y = 0.009999000199950014
x = float(input("Enter value for x: "))
y= 1/(x+(1/(x+(1/(x+(1/x))))))
print("y =", y)
LAB
Estimated time
15-20 minutes
Level of difficulty
Easy
Objectives
• improving the ability to use numbers, operators, and arithmetic operations in Python;
• using the print() function's formatting capabilities;
• learning to express everyday-life phenomena in terms of programming language.
Scenario
Your task is to prepare a simple code able to evaluate the end time of a period of time, given as a number of minutes (it could be arbitrarily large). The start time is given as a pair of hours (0..23) and minutes (0..59). The result has to be printed to the console.
hour = int(input("Starting time (hours): "))
mins = int(input("Starting time (minutes): "))
dura = int(input("Event duration (minutes): "))
# put your code here
For example, if an event starts at 12:17 and lasts 59 minutes, it will end at 13:16.
Test Data
Sample input: 12 17 59
Expected output: 13:16
Sample input: 23 58 642
Expected output: 10:40
Sample input: 0 1 2939
Expected output: 1:0
121%60=1
34%24=10
hour = int(input("Starting time (hours): "))
mins = int(input("Starting time (minutes): "))
dura = int(input("Event duration (minutes): "))
total_time=hour*60
total_time=total_time + mins + dura
print((total_time//60)%24, end=":")
print(total_time%60)
Комментарии