LAB
Objectives
Scenario
Your task is to complete the code in order to evaluate the following expression:
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.009999000199950014
Sample input: -5
Expected output:
y = -0.19258202567760344
Code I wrote:
x = float(input("Enter value for x: "))
y=1/(x+(1/(x+(1/(x+(1/x))))))# Write your code here.
print("y =", y)
LAB
Objectives
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.
For example, if an event starts at 12:17 and lasts 59 minutes, it will end at 13:16.
Don't worry about any imperfections in your code - it's okay if it accepts the invalid time - the most important thing is that the code produce valid results for valid input dat.
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
Used ChatGPT for code:
start_hour = int(input("Enter the starting hour (0-23): "))
start_minute = int(input("Enter the starting minute (0-59): "))
duration_minutes = int(input("Enter the duration in minutes: "))
start_total_minutes = start_hour * 60 + start_minute
end_total_minutes = (start_total_minutes + duration_minutes) % 1440
end_hour = end_total_minutes // 60
end_minute = end_total_minutes % 60
print("End time: {:02d}:{:02d}".format(end_hour, end_minute))
Explanation: