Python Functions and Errors: Time, Triangle, Bonus, and Digits
Classified in Computers
Written at on English with a size of 4.09 KB.
TIME DIFFERENCE
def time_difference(time1, time2):
time1=time_to_seconds(time1)
time2=time_to_seconds(time2)
diffinsecond=time2-time1
hours=diffinsecond//3600
minutes=(diffinsecond-(hours*3600))//60
seconds=diffinsecond-(hours*3600)-(minutes*60)
return(make_time_string(hours,minutes,seconds))
# Predefined helper functions. Do not edit them.
def time_to_seconds(time):
x = list(map(int, time.split(":"))
return x[0] * 3600 + x[1]*60 + x[2]
def make_time_string(hours, mins, seconds):
return "{:02d}:{:02d}:{:02d}".format(hours, mins, seconds)
TYPE OF TRIANGLE
def triangle(side1, side2, side3):
if side1+side2<>
return "Not a triangle"
elif side1==side2 and side2==side3:
return "Equilateral"
elif... Continue reading "Python Functions and Errors: Time, Triangle, Bonus, and Digits" »