Evaluate the following numerical expressions in your head, then use the Python interpreter to check your results:
>>> 5 % 2
>>> 9 % 5
>>> 15 % 12
>>> 12 % 15
>>> 6 % 6
>>> 0 % 7
You look at the clock and it is exactly 2pm. You set an alarm to go off in 51 hours.
Write a Python program to solve the general version of the above problem. Ask the user for the time now (in hours), and ask for the number of hours to wait. Your program should output what the time will be on the clock when the alarm goes off.
Assume the days of the week are numbered 0,1,2,3,4,5,6 from Sunday to Saturday. Write a function which is given the day number, and it returns the day name (a string).
Give the logical opposites of these conditions
a > b
a >= b
a >= 18 and day == 3
a >= 18 and day != 3
What do these expressions evaluate to?
3 == 3
3 != 3
3 >= 4
not (3 < 4)
Write a function which is given an exam mark, and it returns a string the grade for that mark according to this scheme:
Mark | Grade |
>= 75 | First |
[70 - 75) | Upper Second |
[60 - 70) | Second |
[45 - 50) | F1 Supp |
[40 - 45) | F2 |
< 40 | F3 |
The square and round brackets denote closed and open intervals. A closed interval includes the number, and open interval excludes it. So, 39.99999 gets grade F3, but 40 gets grade F2. Assume
xs = [83, 75, 74.9, 70, 69.9, 65, 60, 59.9, 55, 50, 49.9, 45, 44.9, 40, 39.9, 2, 0]
Test your function by printing the mark and the grade for all the elements in this list.
Write a function find_hypot which, given the length of two sides of a right-angled triangle, returns the length of the hypotenuse. (Hint: x ** 0.5 will return the square root.)