Python-day02 while nesting loops

Source: Internet
Author: User

While loop
1, output to print a rectangle composed of #, its own definition of length and width.
#-*-encoding:utf-8-*-
‘‘‘
This is the script for start Docker containor!
Auth:cuishuai
‘‘‘
height = Int (input ("Height:"))
width = Int (input ("width:"))
Num_height = 1

While num_height <= height:
Num_width = 1
While Num_width <= width:
Num_width + = 1
Print ("#", end= "")
Num_height + = 1
Print ()

2, output as Shape
   *
   *
   * * *
   * * * *
#-*-encoding:utf-8-*- '
This is the script for start Docker containor!
Auth:cuishuai
'
width  = Int (Input ("width:"))
Num_width = 1
While num_width <= width:
     print ("#" *num_width,end= "\ n")
    num_width + = 1
3, Output 2 flashback graphic:
  * * * * *
& nbsp * * *
  * *
  *
#-*-encoding:utf-8-*-
"
This is the script for start Docker containor!
Auth:cuishuai
'
width  = Int (Input ("width:"))
While width > 0:
    print ("#" * Width,end= "\ n")
    Width-= 1

The second implementation, using nested loops:
#-*-encoding:utf-8-*-
"
This is the script for start Docker containor!
Auth:cuishuai
'
width  = Int (Input ("width:"))
While width > 0:
    num_width = Width
    while num_width > 0:
        print ("*", end= "")
        Num_width-= 1
    print ()
    Width-= 1

5, Output 99 multiplication table
#-*-encoding:utf-8-*-
"
This is the script for start Docker containor!
Auth:cuishuai
'
width  = 1
While width <= 9:
    num_width = 1
  & nbsp While Num_width <= width:
        print (str (num_width) + "*" +str (width) + "=" +str (num_width*width), end= "\ T")
        num_width + = 1
     Print ()
    width + = 1
Flashback 99 Table
#-*-encoding:utf-8-*-
"'
This is the script for start Docker containor!
Auth:cuishuai
"'
width  = 9
While width > 0:
    num_width = 1
     While Num_width <= width:
        print (str (num_width) + "*" +str ( width) + "=" +str (num_width*width), end= "\ T")
        num_width + = 1
     print ()
    Width-= 1

Note: end= represents the end of each line, \ n denotes a newline character, \ t represents a tab

Python-day02 while nesting loops

Related Article

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.