Question: Write a program that asks the user to enter a number of seconds, and works as follows:
There are 60 seconds in a minute. If the number of seconds
The "timeit" answer above that declares divmod to be slower has seriously flawed logic.
Test1 calls operators.
Test2 calls the function divmod, and calling a function has overhead.
A more accurate way to test would be:
import timeit
def moddiv(a,b):
q= a/b
r= a%b
return q,r
a=10
b=3
md=0
dm=0
for i in range(1,10):
c=a*i
md+= timeit.timeit( lambda: moddiv(c,b))
dm+=timeit.timeit( lambda: divmod(c,b))
print("moddiv ", md)
print("divmod ", dm)
moddiv 5.806157339000492
divmod 4.322451676005585
divmod is faster.