a = 1;
b = 2;
c = a + b
print (c)
3
import time
starttime = time.time()
product = 1
for i in range(1 ,100):
product = product * i
endtime = time.time()
print('The result is %s digits long.'%(len(str(product))))
print('took %s seconds to calculate'%(endtime-starttime))
The result is 156 digits long. took 0.00014781951904296875 seconds to calculate
print ("Enter A")
A = input()
import time
starttime = time.time()
s = 0
for i in range(1, A):
s = s + i
endtime = time.time()
print (sum)
print ('took %s seconds to calculate'%(endtime-starttime))
Enter A 4
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-35-422190daf25d> in <module>() 4 starttime = time.time() 5 s = 0 ----> 6 for i in range(1, A): 7 s = s + i 8 TypeError: 'str' object cannot be interpreted as an integer