Print multiplication table

Source: Internet
Author: User
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>>> 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.