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