# WAP TO FIND THE REVERSE OF THE GIVEN NUMBER number = int(input("Enter a value:")) n = number # initialization reverse = 0 while n != 0: ind_dig = n % 10 reverse = reverse * 10 + ind_dig n = n // 10 print("The Reverse of the {} is = {}".format(number,reverse)) =================================================================== In C: ==== for(init;condi;update) { block of code; } for loop in Python: =================== for ==> keyword for is a loop statement which we can use to define the block/group of actions on individual element of the certain group values/collection etc. ex: 1 to 100 blockofcode ==> 1 block of code ==> 2 Note: ==== for cannot use on numbers directly. for in number: ==> error Syntax: for loop-variable in range(): block of actions for loop-variable in collection: block of actions a = 100 b = 123.234 c = [1,2,3,4,5,6] # WAP IN PYTHON TO PRINT MULTIPLICATION TABLE FOR THE GIVEN NUMBER. # using while loop """ 7 X 1 = 7 7 X 2 = 14 7 X 3 = 21 ..... 7 X 10 = 70 we should do the iteration from 1 to 10 for the finding the multiplication table. """ num = int(input("Enter an integer:")) # i = 1 # # while i <= 10: # result = num * i # print(num," X ",i," = ",result) # i += 1 for i in range(1,11): result = num * i print(num,"X ",i,"=",result) =================================================== # WAP TO FIND THE SUM OF ALL EVEN NUMBERS FROM 100 TO 1 """ range(10) ==> 0 to 9 range(1,10) ==> 1 to 9 ==> forward range ==> no need to use step factor by default, the step factor value = '1' range(1,30,3) ==> 1 4 7 10 ... reverse ranging range(100,1) ==> 100 99 98 not possible range(100,1,-1) => 100,99,98,... for i in range(100,1,-1): print(i,end = "\t") """ even_sum = 0 # for i in range(100,0,-1): # if i % 2 == 0: # even_sum += i for i in range(100,0,-2): even_sum = even_sum + i print("The Sum of all even numbers from the range 100 to 0 is = ",even_sum) ===================================== i = 100 while i >= 1: if i % 2 == 0: sum += i =================================================== Loops with nesting ================== Nested Loops: ============ outer-loop: inner-loop: for: while: while: for: Note: ==== like C, C++, Java the python does not support do-while. # WAP TO FIND ALL PALINDROME NUMBERS FROM 1000 TO 2000. """ Palindrome Number: reverse(original-number) == original-number ex: n = 1221 rev = 1221 rev == n ==> Palindrome """ # for num in range(1000,2001): # str_num = str(num) # rev_str = str_num[::-1] # num_rev = int(rev_str) # if num_rev == num: # print(num,end = "\t") for num in range(1000,2001): n = num reverse = 0 while n != 0: ind_dig = n % 10 reverse = reverse * 10 + ind_dig n = n // 10 if reverse == num: print(num,end = "\t") ==================================================== Assignment: ========== WAP IN PYTHON TO PRINT ALL PRIME NUMBERS FROM 300 TO 100. prime number ==> number which can have only two factors: 1 and itself for i in range(300,100,-1): for j in range(2,i): if i % j != 0: