Introduction To Python-1
Introduction To Python-1
While (condition)
If satisfied the program will be executed otherwise terminate
the program.
Pr-4:- FACTORIAL OF A NUMBER.
# change the value for a different result
num = int(input("enter the number"))
factorial = 1
# check if the number is negative, positive or zero
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
PR-5:- Python program to check Armstrong number.
n = int(input("Enter a number: "))
if n == s:
else:
if Sum == Number:
print("\n%d is a Krishnamurthy Number." %Number)
else:
print("%d is Not a Krishnamurthy Number." %Number)
if num == 1:
print(num, "is not a prime number")
elif num > 1:
# check for factors
for i in range(2, num):
if (num % i) == 0:
# if factor is found, set flag to True
flag = True
# break out of loop
break