0% found this document useful (0 votes)
15 views3 pages

Introduction To Python-1

introduction of python

Uploaded by

pauloindrisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Introduction To Python-1

introduction of python

Uploaded by

pauloindrisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

LOOP

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: "))

#initialize the sum


s=0
t=n
while t > 0:
digit = t % 10
s += digit ** 3
t //= 10

# display the result

if n == s:

print(n,"is an Armstrong number")

else:

print(n,"is not an Armstrong number")

PR 6:- Python program to check PERFECT number.


n = int(input("Enter any number: "))
sum1 = 0
for i in range(1, n): // it means for loop assignment and condition.
if(n % i == 0):
sum1 = sum1 + i
if (sum1 == n):
print("The number is a Perfect number!")
else:
print("The number is not a Perfect number!")

PR 7:- Python program to check PALINDROME number.


n=int(input("Enter number:"))
temp=n
rev=0
while(n>0):
dig=n%10
rev=rev*10+dig
n=n//10
if(temp==rev):
print("The number is a palindrome!")
else:
print("The number isn't a palindrome!")

PR-8: Python program to check KRISHNAMURTI number.

Number = int(input("Enter the Number to Check Krishnamurthy Number = "))# 145


Sum = 0
Temp = Number# Temp=145

while Temp > 0:


fact = 1
i=1
rem = Temp % 10

while i <= rem:


fact = fact * i
i=i+1
print('Factorial of %d = %d' %(rem, fact))
Sum = Sum + fact
Temp = Temp // 10

print("The Sum of the Digits Factorials = %d" %Sum)

if Sum == Number:
print("\n%d is a Krishnamurthy Number." %Number)
else:
print("%d is Not a Krishnamurthy Number." %Number)

PR9:- WRITE A PROGRAM TO PRINT FIBONACCI SERIES.


Number = int(input("\nPlease Enter the Range : "))

# Initializing First and Second Values


i=0
First_Value = 0
Second_Value = 1

# Find & Displaying


while(i < Number):
if(i <= 1):
Next = i
else:
Next = First_Value + Second_Value
First_Value = Second_Value
Second_Value = Next
print(Next)
i=i+1
PR9:- WRITE A PROGRAM TO check if a number is prime or not

num = int(input("Enter a number"))


# define a flag variable
flag = False

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

# check if flag is True


if flag:
print(num, "is not a prime number")
else:
print(num, "is a prime number")

You might also like