Python US time zones

Use a dictionary whose keys are the names of the time zones and whose values are offsets from the Eastern time zone.
Write a program that converts a time from one time zone to another. The user enters the time in the usual American way, such as 3:48pm or 11:26am. The first time zone the user enters is that of the original time and the second is the desired time zone. The possible time zones are Eastern, Central, Mountain, or Pacific.

Time: 11:48pm
Starting zone: Pacific
Ending zone: Eastern
2:48am


d = {'eastern':0, 'central': 1, 'mountain':2,'pacific':3}
enter_time =
input('Enter the time in this format 11:48pm or am: ')
enter_starting_zone =
input('Enter Eastern, Central, Mountain, or Pacific starting zone: ')
starting_zone = enter_starting_zone[:
1].upper() + enter_starting_zone[1:len(enter_starting_zone)]
enter_starting_zone = enter_starting_zone.lower()
enter_starting_zone =d[enter_starting_zone]
first_part =
int(enter_time[:2])
second_part =
int(enter_time[3:5])
am_pm = enter_time[-
2:]
L = []
for i in range(1, 13):
    L.append(i)
print('Time: ', enter_time)
print('Starting zone: ', starting_zone)
print('Ending zone: Eastern')
zbir = first_part + enter_starting_zone
if am_pm == 'am' and zbir <= 11:
   
print('Time is: ', zbir,':',second_part,am_pm )
elif am_pm == 'am' and zbir == 12:
   
print('Time is: ', zbir, ':', second_part, '0pm')
elif am_pm == 'am' and zbir > 12:
   
print('Time is: ', zbir%12, ':', second_part, 'pm')
elif am_pm == 'pm' and zbir <= 11:
   
print('Time is: ', zbir,':',second_part,am_pm )
elif am_pm == 'pm' and zbir == 12:
   
print('Time is: ', zbir, ':', second_part, '0am')
elif am_pm == 'pm' and zbir > 12:
   
print('Time is: ', zbir%12, ':', second_part, 'am')

SOLUTION:

Enter the time
in this format 11:48pm or am: 11:58am
Enter Eastern, Central, Mountain,
or Pacific starting zone: pacific
Time: 
11:58am
Starting zone:  Pacific
Ending zone: Eastern
Time
is:  2 : 58 pm

Коментари

Популарни постови са овог блога

Python Fan functions

Python StopWatch milliseconds

Python Accounting