0% found this document useful (0 votes)
52 views

Week 6

The document contains 8 programming problems involving various mathematical and logical concepts in Python. It includes problems to check for palindromes, find digit frequencies, print ASCII values, find factors, calculate factorials, find prime numbers, check for different types of numbers, and print the Fibonacci series. The problems cover basic loops, strings, mathematical operations, and conditionals in Python.

Uploaded by

mulham
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Week 6

The document contains 8 programming problems involving various mathematical and logical concepts in Python. It includes problems to check for palindromes, find digit frequencies, print ASCII values, find factors, calculate factorials, find prime numbers, check for different types of numbers, and print the Fibonacci series. The problems cover basic loops, strings, mathematical operations, and conditionals in Python.

Uploaded by

mulham
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Week 6:

1. Write a Python program to check whether a number is palindrome or not.

num=int(input("Enter a number:"))
temp=num
rev=0
rem=0
while(num>0):
rem=num%10
rev=rev*10+rem
num=num//10
if(temp==rev):
print("The number is palindrome!")
else:
print("Not a palindrome!")

2. Write a Python program to find frequency of each digit in a given integer.

n=int(input("Enter any Number"))


print("Digit\tFrequency")
for i in range(0,10):
count=0;
temp=n;
while temp>0:
digit=temp%10
if digit==i:
count=count+1
temp=temp//10;
if count>0:
print(i,"\t",count)

3. Write a Python program to print all ASCII character with their values.

i=0

while i<=255:
print(i,"=",chr(i), end=' ')
i += 1
4. Write a Python program to find all factors of a number.

n =int(input("enter any number:"))

print("The factors of ",n,"are:")

for i in range(1,n+1):
if n % i == 0:
print(i,end=' ')

5. Write a Python program to calculate factorial of a number.

n= int(input("Enter a number: "))


fact= 1
if n< 0:
print("Sorry, factorial does not exist for negative numbers")
elif n== 0:
print("The factorial of 0 is 1")
else:
for i in range(1,n + 1):
fact= fact*i
print("The factorial of",n,"is",fact)

6. Write a Python program to print all Prime numbers between 1 to n.

n=int(input("upto which number:"))


count=0
print("the prime numbers from 1 to",n,"are")
for i in range(1,n+1):
count=0
for j in range(1,i+1):
if(i%j==0):
count+=1
if count==2:
print(i,end=' ')

7. Write
a Python program to check whether a
number is Armstrong number or Strong or Prime
Number or Perfect number or magic number or
not

print("menu list")
print("---------")
print("1. for checking Armstrong number")
print("2. for checking strong Number")
print("3. for checking Prime Number")
print("4. for checking Perfect Number")
print("5. for checking magic number")
choice=int(input("enter your choice :"))
#Armstrong number
if(choice==1):
num=int(input("enter any number:"))
order = len(str(num))
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** order
temp //= 10
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")

#Strong number
if(choice==2):
sum=0
num=int(input("Enter a number:"))
temp=num
while(num):
i=1
fact=1
rem=num%10
while(i<=rem):
fact=fact*i
i=i+1
sum=sum+fact
num=num//10
if(sum==temp):
print("Given number is a strong number")
else:
print("given number is not a strong number")
#Prime number
if(choice==3):
num = int(input("Enter a number: "))
count=0
for i in range(1, num+1):
if num % i == 0:
count+=1
if count==2:
print(num, "is a prime number")
else:
print(num, "is not a prime number")
#Perfect Number
if(choice==4):
n=int(input("ente any number:"))
sum = 0
for i in range(1, n):
if n % i == 0:
sum += i
if(sum == n):
print(n,"is perfect number")
else:
print(n,"is not perfect number")
#Magic Number
if(choice==5):
n=int(input("enter any number:"))
sum = 0
while (n > 0 or sum > 9):
if (n == 0):
n = sum
sum = 0
sum = sum + n % 10
n = int(n / 10)
if (sum==1):
print("The given number is Magic Number.")
else:
print("The given is not a Magic Number.")

8. Write a Python program to print Fibonacci series up to n terms.

n=int(input("upto which number:"))


f=0
s=1
print("the fibonancci series upto",n,"is:")
t=f+s
while(t<=n):
print(t,end=' ')
f=s
s=t
t=f+s

You might also like