# WAP TO FIND THE SUM OF DIGITS OF A GIVEN NUMBER. """ 987654 How to get individual digits from a number? =========================================== by modulo division of number and floor division of number with 10, we can get individual digits -> then continue to find the sum of digits of a number. """ number = int(input("Enter a value:")) # 987654 sumDigits = 0 n = number # initialization # 987654 while n > 0: # condition indDigits = n % 10 sumDigits = sumDigits + indDigits n = n // 10 # update print("The Sum of Digits of",number,"is = ",sumDigits) ================================================================== Link for while loop practice programs ===================================== https://csiplearninghub.com/questions-of-while-loop-in-python/ ============================================================================== For Loop: ========= range() ======= -> an operator which can be used to generate numbers from the specified range Syntax: range(start) range(start, stop) range(start, stop, step) a = range(10) # range() can generate values from '0' default # until start - 1 print(a) b = range(10,20) print(b) c = range(1,100,15) # generate numbers from 1 to 99 with difference of 15 print(c) for a in range(10): print(a) print() for b in range(10,20): print(b) print() for c in range(1,100,15): print(c) ===================================================== # WAP TO FIND THE SUM OF ALL NATURAL NUMBERS TILL THE SPECIFIED VALUE. # natural numbers can always start with '1' by default # whole numbers can always start with '0' specifiedValue = int(input("Enter a value:")) sumNaturals = 0 for i in range(1,specifiedValue+1): # print(i) sumNaturals = sumNaturals + i print("The Sum of Natural Numbers = ",sumNaturals) sumNaturalNumbers = specifiedValue * (specifiedValue + 1)//2 print(sumNaturalNumbers) =================================================================== # WAP TO PRINT ALL INDIVIDUAL CHARACTERS OF THE STRING. string = "Python for Devops" print("The Characters of the given string are = ") for i in string: print(i,end = " ") String Concatenation: ===================== Joining of one string at the end of first string is called as "String concatenation". -> represented with an operator ==> '+' Syntax: String1 + string2 # WAP TO CHECK WHETHER THE GIVEN STRING IS PALINDROME OR NOT. """ String palindrome ==> when reverse of the given string == original string Ex: o = "level" reverse = "level" o == reverse ==> Palindrome """ string = input("Enter some string:") reveseString = "" # to store the result after the reverse operation # we should take individual characters of the string for i in string: # print(i,end = " ") # should find the reverse of the string using concatenation reveseString = i + reveseString # print(reveseString) if reveseString == string: print(string,"is palindrome") else: print(string, "is not palindrome")