1. Print the multiplication table of 8 first:
for looper in [1,2,3,4,5]: print looper," times 8 = ",looper*8
for looper in range (1,5): print looper,"times 8 =",looper*8for looper in range (1,10): print looper,"times 8 =",looper*8
Result:
>>> ================================ RESTART ================================>>> 1 times 8 = 82 times 8 = 163 times 8 = 244 times 8 = 325 times 8 = 40>>>
================================ RESTART ================================>>> 1 times 8 = 82 times 8 = 163 times 8 = 244 times 8 = 32>>> ================================ RESTART ================================>>> 1 times 8 = 82 times 8 = 163 times 8 = 244 times 8 = 321 times 8 = 82 times 8 = 163 times 8 = 244 times 8 = 325 times 8 = 406 times 8 = 487 times 8 = 568 times 8 = 649 times 8 = 72>>>
You must note that range () = [,] instead of [, 5] range () provides a list of numbers starting with the given first number, end before the given last number.
2. Print the common multiplication table.
x=int(raw_input("what multiplication table would you like?\n"))for i in range (1,11): print x,"x",i,"=",x*iprint "\n\n***********************************************\n\n"
x=int(raw_input("what multiplication table would you like?\n"))m=int(raw_input("how high do you want to go ?\n"))for i in range (1,m+1): print x,"x",i,"=",x*i
Running result:
>>> ================================ RESTART ================================>>> what multiplication table would you like?55 x 1 = 55 x 2 = 105 x 3 = 155 x 4 = 205 x 5 = 255 x 6 = 305 x 7 = 355 x 8 = 405 x 9 = 455 x 10 = 50***********************************************what multiplication table would you like?7how high do you want to go ?127 x 1 = 77 x 2 = 147 x 3 = 217 x 4 = 287 x 5 = 357 x 6 = 427 x 7 = 497 x 8 = 567 x 9 = 637 x 10 = 707 x 11 = 777 x 12 = 84>>>