Basic Python PROGRAMS
Basic Python PROGRAMS
output :
Program 2 : WAP to input 3 numbers and print the greatest number using nested if.
output :
Program 3 : WAP to input a number and check whether it is prime number or not.
output :
Program 4 : WAP to find sum of elements in list
total = 0
# creating a list
list1 = [11, 5, 17, 18, 23]
# Iterate each element in list
# and add them in variable total
for ele in range(0, len(list1)):
total = total + list1[ele]
Output :
Program 5. WAP to find Factorial of a number using recursion
def recur_factorial(n):
if n == 1:
return n
else:
return n*recur_factorial(n-1)
num = 7
# check if the number is negative
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
print("The factorial of", num, "is", recur_factorial(num))
output :
: