Mid Sem Questions
Mid Sem Questions
Write a program that asks the user for an hour between 1 and 12 and for how many hours in the
future they want to go. Print out what the hour will be that many hours into the future. An example
is shown below. [5]
Enter hour: 8
How many hours ahead? 5
New hour: 1 o'clock
Solution:
if new_time<0:
elif new_time==0:
else:
Q.Show the result of evaluating each expression. Be sure that the value is in the proper form to
indicate its type (int or float). If the expression is illegal, explain why [1+2+2]
Solution: 4.0 / 10.0 + 3.5 * 2 =0.4 + 7.0 =7.4 output is float. (Each step carry marks giving just final
value will give only 0.5 marks)
b) sqrt (5.0 - - - 4.5) + 7 *3 (yes there are three minus symbols its not a typing error)
Solution: Two answers are possible if someone has written that error will be generated because
import math and math.sqrt is not written he/she will get full marks.
Also if you have assumed that everything is included then answer will be
= sqrt(0.5)+7*3
= 0.707+21 .
= 21.707 output is float (Each step carry marks giving just final value will give only 0.5 marks)
c) 3 ** 2 // 3 + 10% 3
=9//3+10%3
=3+1
=4 Output is integer (Each step carry marks giving just final value will give only 0.5 marks)