In this article i am gone to share a Coursera Course: Learn to Program: The Fundamentals Week 1 Assignment | Programming Assignment: Assignment 1 Time Zones Solution with you..
What to do
There are several functions that you will need to implement. We have listed the functions roughly in order of complexity. Each function body will be quite short. You can submit your assignment for feedback once every hour up until the deadline; we recommend that you do this at least once early on in order to make sure you can submit properly.
- Step 1: Download the starter code
- Step 2: Complete the body of function seconds_difference
- Step 3: Complete the body of function hours_difference
- Step 4: Complete the body of function to float_hours
- Step 5: Write functions get_hours, get_minutes and get_seconds
- Step 6: Complete the bodies of functions time_to_utc and time_from_utc
- Step 7: Submit your work.
Programming Assignment: Assignment 1 Time Zones
- You first need to create a python file give name assignment1.py
- Copy all the code paste in a file and then save it.
- Now upload your file on Coursera Course assignment and then click on submit.
assignment1.py
def seconds_difference(time_1, time_2):
“”” (number, number) -> number
Return the number of seconds later that a time in seconds
time_2 is than a time in seconds time_1.
>>> seconds_difference(1800.0, 3600.0)
1800.0
>>> seconds_difference(3600.0, 1800.0)
-1800.0
>>> seconds_difference(1800.0, 2160.0)
360.0
>>> seconds_difference(1800.0, 1800.0)
0.0
“””
return time_2 – time_1
def hours_difference(time_1, time_2):
“”” (number, number) -> float
Return the number of hours later that a time in seconds
time_2 is than a time in seconds time_1.
>>> hours_difference(1800.0, 3600.0)
0.5
>>> hours_difference(3600.0, 1800.0)
-0.5
>>> hours_difference(1800.0, 2160.0)
0.1
>>> hours_difference(1800.0, 1800.0)
0.0
“””
return (time_2 – time_1)/3600.0
def to_float_hours(hours, minutes, seconds):
“”” (int, int, int) -> float
Return the total number of hours in the specified number
of hours, minutes, and seconds.
Precondition: 0 <= minutes < 60 and 0 <= seconds < 60
>>> to_float_hours(0, 15, 0)
0.25
>>> to_float_hours(2, 45, 9)
2.7525
>>> to_float_hours(1, 0, 36)
1.01
“””
return (hours + (minutes/60) + (seconds/3600))
def to_24_hour_clock(hours):
“”” (number) -> number
hours is a number of hours since midnight. Return the
hour as seen on a 24-hour clock.
Precondition: hours >= 0
>>> to_24_hour_clock(24)
0
>>> to_24_hour_clock(48)
0
>>> to_24_hour_clock(25)
1
>>> to_24_hour_clock(4)
4
>>> to_24_hour_clock(28.5)
4.5
“””
return hours % 24
### Write your get_hours function definition here:
def get_hours(time):
“””(int) -> int
Return the number of hours that have
elapsed since midnight, as seen on a 24-hour clock
>>> get_hours(3800)
1
“””
x= time/3600
return int(to_24_hour_clock(x))
### Write your get_minutes function definition here:
def get_minutes(time):
“””(int) -> int
Return the number of minutes that have
elapsed since midnight as seen on a clock.
>>> get_minutes(3800)
3
“””
x=int(time/3600)
z= time -(x*3600)
y=z/60
return int(y)
### Write your get_seconds function definition here:
def get_seconds(time):
“””(int) -> int
Return the number of seconds that have
elapsed since midnight as seen on a clock.
>>> get_seconds(3800)
20
“””
x=int(time/3600)
z= time -(x*3600)
y=z%60
return int(y)
def time_to_utc(utc_offset, time):
“”” (number, float) -> float
Return time at UTC+0, where utc_offset is the number of hours away from
UTC+0.
>>> time_to_utc(+0, 12.0)
12.0
>>> time_to_utc(+1, 12.0)
11.0
>>> time_to_utc(-1, 12.0)
13.0
>>> time_to_utc(-11, 18.0)
5.0
>>> time_to_utc(-1, 0.0)
1.0
>>> time_to_utc(-1, 23.0)
0.0
“””
time_2 = (time -(utc_offset))
return (to_24_hour_clock(time_2))
def time_from_utc(utc_offset, time):
“”” (number, float) -> float
Return UTC time in time zone utc_offset.
>>> time_from_utc(+0, 12.0)
12.0
>>> time_from_utc(+1, 12.0)
13.0
>>> time_from_utc(-1, 12.0)
11.0
>>> time_from_utc(+6, 6.0)
12.0
>>> time_from_utc(-7, 6.0)
23.0
>>> time_from_utc(-1, 0.0)
23.0
>>> time_from_utc(-1, 23.0)
22.0
>>> time_from_utc(+1, 23.0)
0.0
“””
time_2 = (time +(utc_offset))
return (to_24_hour_clock(time_2))
Note: after submit please wait your marks will we updated within 2 minutes.. If you get any error tell me i will resolved it.. Thank you..