LOOP STATEMANTS ================= ==> ALSO CALLED AS "ITERATIVE STATEMENTS" EX: PRINTING NUMBERS FROM 1 TO 10. i = 1 print(i) # 1 i = i + 1 print(i) # 2 i = i + 1 print(i) # 3 i = i + 1 print(i) # 4 i = i + 1 print(i) # 5 i = i + 1 print(i) # 6 i = i + 1 print(i) # 7 i = i + 1 print(i) # 8 i = i + 1 print(i) # 9 i = i + 1 print(i) # 10 ==> to define loops: three requirements: 1) initialization 2) condition 3) update ==> two types of loop statements: 1) while loop 2) for loop Note: ==== like other high-level programming languages, python does not support "do-while". 1) while loop ========== Syntax: ===== initilialization while condition: statement-1 statement-2 update out side loop statements # WAP IN PYTHON TO PRINT NUMBERS FROM 1 TO 10 USING WHILE LOOP. i = 1 # initialization # i is called as "loop variable/iteration variable" while i <= 10: # condition print(i) i = i + 1 # update ============================ # WAP IN PYTHON TO PRINT NUMBERS FROM 1 TO 10 USING WHILE LOOP. i = 1 # initialization # i is called as "loop variable/iteration variable" while i <= 10: # condition print(i,end = '\t') # i = i + 1 # update i += 1 ============================= # WAP IN PYTHON TO PRINT THE NUMBERS FROM 10 TO 1 USING WHILE LOOP. i = 10 # initialization while i >= 1: # condition print(i,end = '\t') i -= 1 # update ======================== # WAP TO PRINT THE MULTIPLICATION TABLE OF THE GIVEN INTEGER. num = int(input("Enter an integer:")) i = 1 # initialization while i <= 10: # condition print(num,"X",i,"=",num * i) i += 1 # update ====================================== # WAP IN PYTHON TO PRINT THE MULTIPLE OF THE GIVEN INTEGER. # 7, 14, 21, 28,... num = int(input("Enter an integer:")) i = 1 while i <= 100: if i % 7 == 0: print(i,end = '\t') i += 1 ========================== # WAP TO FIND THE SUM OF INDIVIDUAL DIGITS OF THE GIVEN NUMBER. """ 9876 ==> 9 + 8 + 7 + 6 ==> 30 9876 ==> 9 x 10^3 + 8 x 10^2 + 7 x 10^1 + 6 x 10^0 9876, DIVIDE WITH 10 QUOTIENT ==> 987 98 9 0 REMAINDER ==> 6 7 8 9 SUM OF REMAINDER """ number = int(input("Enter an integer:")) # 9876 n = number # n = 9876 sum_dig = 0 while n != 0: ind_dig = n % 10 # 9%10 ==> 6 7 8 9 sum_dig += ind_dig # 30 n //= 10 # 987 98 9 0 print("The Sum of Individual Digits of",number,"is = ",sum_dig) ================================================== # WAP IN PYTHON TO COUNT THE NUMBER OF DIGITS OF THE GIVEN NUMBER. num = int(input("Enter an integer:")) n = num cnt_dig = 0 while n > 0: n //= 10 cnt_dig += 1 print("The Number of Digits in ", num, "is = ", cnt_dig)