The document contains code snippets for finding the greatest number among four input numbers, calculating the factorial of a given number, reversing a number, checking if a number is a palindrome, and calculating the sum of all digits in a number. Each code snippet accepts a number as input, performs operations on that number, and outputs a result.
The document contains code snippets for finding the greatest number among four input numbers, calculating the factorial of a given number, reversing a number, checking if a number is a palindrome, and calculating the sum of all digits in a number. Each code snippet accepts a number as input, performs operations on that number, and outputs a result.
The document contains code snippets for finding the greatest number among four input numbers, calculating the factorial of a given number, reversing a number, checking if a number is a palindrome, and calculating the sum of all digits in a number. Each code snippet accepts a number as input, performs operations on that number, and outputs a result.
• if (n1>n2) and (n1>n3) and (n1>n4): • L1 = [num1, num2, num3, num4]
• print("n1 is Greater") • elif (n2>n1) and (n2>n3) and (n2>n4): • maximum = max(L1) • print("n2 is Greater") • elif (n3>n2) and (n3>n1) and (n3>n4): • maxIndex = L1.index(max(L1)) • print("n3 is Greater") • else: • print("Greatest number is number “,str(maxIndex+1)) • print(n4,"is Greater") Factorial of a number • n=int(input("enter no")) • if n < 0: • print(0) • elif n == 0 or n == 1: • print(1) • else: • fact = 1 • while(n > 1): • fact *= n • n -= 1
• print(fact) Reverse of a no • num = 1234 • reversed_num = 0
• while num > 0: #num!=0
• digit = num % 10 • reversed_num = reversed_num * 10 + digit • num //= 10
• print("Reversed Number: " + str(reversed_num))
Check if a number is palindrome • num = 1234 • temp = num • reversed_num=0
• while num > 0: #num!=0
• digit = num % 10 • reversed_num = reversed_num * 10 + digit • num //= 10 • if (temp==reversed_num): • print(str(temp)+’ is palindrome’) Sum of all digits in no • num = 1234 • sum = 0
• while num > 0: #num!=0
• digit = num % 10 • sum= sum + digit • num //= 10
• print(“sum of all digits in Number: " + str(reversed_num))