321# time zone calculator
2
3# enter the time
4valid_time = False
5while not valid_time:
6time = input("Please enter the time (e.g. 13:05)")
7try:
8hours, minutes = time.split(":")
9hours = int(hours)
10minutes = int(minutes)
11if hours < 24 and hours >= 0:
12if minutes < 60 and minutes >= 0:
13valid_time = True
14except:
15print("Invalid time")
16
17# enter the time zone difference
18time_difference = 1
19try:
20time_difference = int(input("Please enter the difference in hours (or leave blank for +1)"))
21except:
22print("Invalid time difference, using a default value of +1")
23
24
25# adjust and display the time
26hours = (hours + time_difference) % 24
27print("The adjusted time is {:02}:{:02}".format(hours, minutes))
28
29# Challenges:
30# 1) Change the default time difference to -1
31# 2) Convert the time from the 24hr clock to the 12hr clock
32# 3) Make it so you can enter a time difference of hours:minutes rather than just hours