You are on page 1of 4

PYTHON

-Kritika Harlalka, XI C1

1) Write a program to accept a number and check whether it is a


perfect number or not.
(A perfect number is equal to the sum of its factors. Example:
6=1+2+3)
2) Write a program to accept two numbers and find their HCF and
LCM.
3) Write a program to print the following series:
a) 1/2+2/4+3/6+.......+n terms
b) 1+2^3+3^5+4^7+.....+n terms
4) Write a program to print the following series:
a) 1 2 3 4
123
12
1
b) A
AB
ABC
ABCD
5) Write a program to display all prime numbers from 1 to n.

ANSWERS:-

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


sum=0
for i in range(1,n//2+1):
if n%i==0:
sum=sum+i
if sum==n:
print("The number is perfect square")
else:
print("The number is not perfect number")
2) a= int(input("Enter first number: "))
b= int(input("Enter the second number: "))

for i in range(1,a):
if a%i==0 and b%i==0:
hcf=i
print("HCF is ",hcf)

lcm= (a*b)//hcf
print("LCM is ",lcm)

3)
a) n= int(input("Enter the end value of the series: "))
sum=0
d= 2

print("Sum of the series: ")


for i in range(1,n+1):
a=i/d
sum=sum+a
d=d+2
print(sum)
b) n=int(input("Enter the end value of the series: "))
import math
print("Total of series: ")
sum=0
p=1
for i in range(1,n+1):
a= math.pow(i,p)
sum= sum+a
p=p+2
print(sum)

4)
a) for i in range(4,0,-1):
for j in range(1,i+1):
print(j,end=" ")
print()
b) for i in range(1,5):
ch="A"
for j in range(1,i+1):
print(ch, end= ' ')
ch=chr(ord(ch)+1)
print()

6) n= int(input("Enter the maximum value of the number: "))

for i in range(1, n+1):


if i>1:
for j in range(2,i):
if i%j==0:
break
else:
print(i)

print()

You might also like