The while loop prints a right triangle:
1 w = int (input ( " Please enter the width of the triangle: " )) 2 y = 0 3 while y <4: # y, the right angle of the right triangle is 4 j = 0 #Number of lines, 0 means the first line 5 s = W . 6 . 7 IF Y == 0: # right triangle at right angles to the upper right corner . 8 the while J < W: . 9 Print ( " {:>} {} " .format (( " * " * S), W)) 10 J + = 1 11 s-= 1 12 Print () 13 is 14 IF Y ==. 1: # right triangle at right angles to the upper left corner 15 the while J < W: 16 Print ( " {: <{}} " .format (( " * " * S), W)) . 17 +. 1 = J 18 is S - =. 1 . 19 Print () 20 is 21 is IF Y == 2: # right triangle at right angles to the lower right corner 22 is the while J < W: 23 is Print ( " {:>} {} " .format (( "* " * (J +. 1 )), W)) 24 J +. 1 = 25 Print () 26 is 27 IF Y ==. 3: # right triangle at right angles to the lower left corner 28 the while J < W: 29 Print ( " {: < {}} " .format (( " * " * (j + 1 )), w)) 30 j + = 1 31 print () 32 33 y + = 1
Operation result === 》
Please enter triangle width: 5
*****
****
***
**
*
*****
****
***
**
*
*
**
***
****
*****
*
**
***
****
*****