def fact(number): if number==1: return 1 else: return number*fact(number-1) n=int(input(“Enter the number:”)) print(“Factorial of the number:” ,fact(n)) OUTPUT:
Write a Python program to reverse a string.
def reverse(string): return string[::-1] s=input(“Enter the string:”) print(“Reverse of the string:” ,reverse(s)) OUTPUT
Write a Python function to multiply all the numbers in a list.
def prolist(lst): pro=1 for x in lst: pro=pro*x return pro lst1=list(map(int,input(“Enter elements of list:”).split())) print(“Product of elements:”,prolist(lst1)) OUTPUT
Write a Python function to sum all the numbers in a list.
def sumlist(lst): return sum(lst) lst1=list(map(int,input(“Enter elements of list:”).split())) print(“Sum of elements:”,sumlist(lst1)) OUTPUT
Write a Python function to find the Max of three numbers.
def max(a,b,c): if a>b and a>c: return a elif b>c: return b else: return c a,b,c=map(int,input(“Enter three numbers:”).split()) print(“Maximum of the three:”,max(a,b,c)) OUTPUT