Solid right angle triangle 2 n=int(input()) for i in range(n): for j in range(i+1): print("*",end=" ") print() for i in range(n): for j in range(i+1): print("*",end=" ") print()
Loops So far we have seen that Python executes code in a sequence and each block of code is executed once. Loops allow us to execute a block of code several times. While Loop Allows us to execute a block of code several times as long as the condition is True . While Loop Example The following code snippet prints the next three consecutive numbers after a given number. Code 1 2 3 4 5 6 a = int ( input ( )) counter = 0 while counter < 3 : a = a + 1 print ( a ) counter = counter + 1 PYTHON Input 4 Output 5 6 7 Possible Mistakes 1. Missing Initialization Code 1 2 3 4 5 6 a = int ( input ( )) while counter < 3 : a = a + 1 print ( a ) counter = counter + 1 print ( "End" ) PYTHON Input 5 Output NameError: name 'counter' is not defined 2. Incorrect Termination Condition Code 1 2 3 4 5 6 7 a = int ( input ( )) counter = 0 condition = ( counter < 3 ) while condition : a =...