In python (use loop, if, else...)
a)Enter a function that calculates the maximum common divider of 2 numbers.
b)Write a function that asks for time in seconds and converts it into hours, minutes, and seconds
a)
Code:
def mcd(a, b):
minimum = min(a, b)
for i in range(2, minimum+1):
if a%i==0 and b%i==0:
mcd = i
return mcd
b)
Code:
def seconds(sec):
#Taking the odd seconds out
sec = sec%86400
#Calculating the hours
hours = int(sec/(36*100))
sec = sec%3600
#Calculating minutess
mins = int(sec/60)
sec = sec%60
print(hours, mins, sec)
seconds(3666)
Output:
PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
Get Answers For Free
Most questions answered within 1 hours.