3.3 Add hours on a clock (24 hour clock)

Python solution

View solution

This is just one of many possible solutions:

original_time = int(input('Enter a time: '))
hours_to_add = int(input('Enter the number of hours to add: '))
new_time = (original_time + hours_to_add) % 24
if new_time == 0:
  print('The new time is 00:00.')
else:
  print('The new time is ' + str(new_time) + ':00.')

Back to programming challenge

Extra Challenge

Modify your program so the new time is displayed as 24:00, if the value of the “new time” is equal to 0.