Wednesday, 6 November 2019

Python Programs 2


Question 1:- Write a program to convert the temperature into Celsius to farehnite, farehnite to Celsius, farehnite to Kelvin, Kelvin to farehnite, Celsius to Kelvin and Kelvin to Celsius.
Answer:-
print("\n\n         MENU      \n")
print("   1. to convert celsius to fahrenheit\n")
print("   2. to convert fahrenheit to celsius\n")
print("   3. to convert fahrenheit to kelvin\n")
print("   4. to convert kelvin to fahrenheit\n")
print("   5. to convert celsius to kelvin\n")
print("   6. to convert kelvin to celsius\n")
ch=eval(input("   enter your choice\n"))
if(ch==1):
    t=eval(input("   enter temperature in celsius\n"))
    t=(t*9/5)+32
    print("   temperature in fahrenheit is",round(t,2))
elif(ch==2):
    t=eval(input("   enter temperature in fahrenheit\n"))
    t=(t-32)*5/9
    print("   temperature in celsius is",round(t,2))
elif(ch==3):
    t=eval(input("   enter temperature in fahrenheit\n"))
    t=((t-32)*(5/9)+273.15)
    print("   temperature in kelvin is",round(t,2))
elif(ch==4):
    t=eval(input("   enter temperature in kelvin\n"))
    t=((t-273.15)*(9/5)+32)
    print("   temperature in fahrenheit is",round(t,2))
elif(ch==5):
    t=eval(input("   enter temperature in celsius\n"))
    t=t+273.15
    print("   temperature in kelvin is",round(t,2))
elif(ch==6):
    t=eval(input("   enter temperature in kelvin\n"))
    t=t-273.15
    print("   temperature in celsius is",round(t,2))
print("\n   Made By Aakash Pramanik Of Class XI-B\n")
Question 2:- Write a program to input 3 sides of the triangle. Find the semi-perimeter and the area by using heron’s formula.
Answer:-
import math
a=eval(input("\n\n   enter the first side\n"))
b=eval(input("   enter the second side\n"))
c=eval(input("   enter the third side\n"))
s=1/2*(a+b+c)
area=math.sqrt(s*(s-a)*(s-b)*(s-c))
print("   semi perimeter of the circle is",s)
print("   area of the trianlge is",round(area,2))
print("\n   Made By Aakash Pramanik Of Class XI-B\n")






Question 3:- Write a program to find the circumference and area of a circle.
Answer:-
pi=3.14
r=eval(input("\n\n   enter the radius\n"))
circum=2*pi*r
area=pi*r*r
print("   circumference of the circle is",round(circum,2))
print("   area of the circle is",round(area,2))
print("\n   Made By Aakash Pramanik Of Class XI-B\n")









Question 4:- Write a program to find area of the park whose inner dimensions has been given.
Answer:-
h=eval(input("\n\n   enter the height\n"))
b=eval(input("   enter the width\n"))
area=h*b
print("   the area of the park is",area)
print("\n   Made By Aakash Pramanik Of Class XI-B\n")










Question 5:- Write a program to find area of the ring whose outer radius and width is given.
Answer:-
pi=3.14
R=eval(input("\n\n   enter the outer radius\n"))
r=eval(input("   enter the inner radius\n"))
area=(pi*R*R)-(pi*r*r)
print("   the area of the ring is",round(area,2))
print("\n   Made By Aakash Pramanik Of Class XI-B\n")










Question 6:- Write a program to input 5 digit numbers and find the sum of the square of the digit and reverse of digit.
Answer:-
n=eval(input("\n\n   enter the five digit number\n"))
m=n
sum=0
rev=0
while(n>=1):
    dig=n%10
    sum=sum+dig*dig
    n=n//10
print("   sum of square of the digit is",sum)
while(m>=1):
    p=m%10
    rev=rev*10+p
    m=m//10
print("   reverse of the digit is",rev)
print("\n   Made By Aakash Pramanik Of Class XI-B\n")

Question 7:- Write a program to find principal, rate and time. Find the simple interest and amount, compound interest and amount.
Answer:-
import math
p=eval(input("\n\n   enter the principal\n"))
r=eval(input("   enter the rate\n"))
t=eval(input("   enter the time\n"))
si=(p*r*t)/1000
a=p*math.pow((1+r/100),t)
ci=a-p
print("   simple interest is",round(si,2))
print("   amount is",round(a,2))
print("   compound interest is",round(ci,2))
print("\n   Made By Aakash Pramanik Of Class XI-B\n")




Question 8:- Write a program to find the T.S.A, C.S.A and volume of cone, cylinder and sphere.
Answer:-
r=eval(input("\n\n   enter the radius\n"))
h=eval(input("   enter the height\n"))
l=eval(input("   enter the length\n"))
pi=3.14
csaofc=pi*r*l
tsaofc=(pi*r*l)+(pi*r*r)
volumeofc=1/3*(pi*r*r*h)
csaofcy=2*pi*r*h
tsaofcy=(2*pi*r*h)+(2*pi*r*r)
volumeofcy=pi*r*r*h
csaofs=4*pi*r*r
tsaofs=4*pi*r*r
volumeofs=4/3*(pi*r*r*r)
print("   csa of cone is",csaofc)
print("   tsa of cone is",round(tsaofc,2))
print("   volume of cone is",round(volumeofc,2))
print("   csa of cylinder is",csaofcy)
print("   tsa of cylinder is",round(tsaofcy,2))
print("   volume of cylinder is",round(volumeofcy,2))
print("   csa of sphere is",round(csaofs,2))
print("   tsa of sphere is",round(tsaofs,2))
print("   volume of sphere is",round(volumeofs,2))
print("\n   Made By Aakash Pramanik Of Class XI-B\n")













Question 9:- In a departmental store, provides the discount of various items for electrical item 10%, for electronic items 20%, for medicine 25% and for garments 15%.
Write a program to prepare a bill inputting the category of the item, name of the item, unit price and quantity. Calculate the discount and GST of 12%. Make a final bill.
Answer:-
category=input("\n\n   enter the category of item\n")
name=input("   enter the name of item\n")
price=eval(input("   enter the  unit price of item\n"))
quantity=eval(input("   enter the quantity of item\n"))
bill=price*quantity
if(category=='electrical'):
    bill=bill-bill*10/100
elif(category=='electronic'):
    bill=bill-bill*20/100
elif(category=='medicine'):
    bill=bill-bill*25/100
elif(category=='garments'):
    bill=bill-bill*15/100
bill=bill+bill*12/100
print("   after adding gst total bill is",round(bill,2))
print("\n   Made By Aakash Pramanik Of Class XI-B\n")

   













Question 10:- Write a program to input 2 numbers and display the largest number.
Answer:-
a=eval(input("\n\n   enter the first numebr\n"))
b=eval(input("   enter the second numebr\n"))
if(a>b):
    print("  ",a,"is greater")
else:
    print("  ",b,"is greater")
print("\n   Made By Aakash Pramanik Of Class XI-B\n")










Question 11:- Write a program to find the smallest number out of 3 numbers.
Answer:-
print("\n\n")
small=100000
for i in range(1,3+1):
    print("   enter",i,"number")
    dig=eval(input())
    if(small>dig):
        small=dig
print("   the smallest number is",small)
print("\n   Made By Aakash Pramanik Of Class XI-B\n")








Question 12:- Write a program to find the greatest of five numbers.
Answer:-
print("\n\n")
big=0
for i in range(1,5+1):
    print("   enter",i,"number")
    dig=eval(input())
    if(dig>big):
        big=dig
print("   the biggest number is",big)
print("\n   Made By Aakash Pramanik Of Class XI-B\n")






Question 13:- Write a program to input the vertices of the triangle and find the area of the triangle.
Answer:-
import math
a=eval(input("\n\n   enter the first side\n"))
b=eval(input("   enter the second side\n"))
c=eval(input("   enter the third side\n"))
s=(a+b+c)/2
area=math.sqrt(s*(s-a)*(s-b)*(s-c))
print("   area of the triangle of the given vertices is",round(area,2))
print("\n   Made By Aakash Pramanik Of Class XI-B\n")







Question 14:- Write a program to input 3 sides of the triangle and check whether it is forming a triangle or not. If it is forming a triangle. What triangle is it and find the area of the triangle.
Answer:-
import math
a=eval(input("\n\n   enter the first side\n"))
b=eval(input("   enter the second side\n"))
c=eval(input("   enter the third side\n"))
if((a+b>c)or(b+c>a)or(c+a>b)):
    print("   sides are forming a triangle")
else:
    print("   sides are not forming a triangle")
if((a*a+b*b==c*c)or(b*b+c*c==a*a)or(c*c+a*a==b*b)):
    print("   triangle is right angled triangle")
elif((a==b)and(b==c)):
    print("   traingle is equilateral triangle")
elif((a==b)or(b==c)or(c==a)):
    print("   triangle is isosceles triangle")
s=(a+b+c)/2
area=math.sqrt(s*(s-a)*(s-b)*(s-c))
print("   area of the triangle is",area)
print("\n   Made By Aakash Pramanik Of Class XI-B\n")
















Question 15:- Write a program to find the age of a person if current date, month and year and birth date, month and year are given.
Answer:-
y1=int(input("\n\n   enter the current year\n"))
m1=int(input("   enter the current month\n"))
d1=int(input("   enter todays date\n"))
y2=int(input("   enter your year of birth\n"))
m2=int(input("   enter your month of birth\n"))
d2=int(input("   enter your date of birth\n"))
if(d1>d2 or d1==d2):
    d=d1-d2
else:
    if(m1==2):
        if(y1%4==0):
            d=d1+29
        else:
            d1=d1+28
    elif(m1==4 or m1==6 or m1==9 or m1==11):
        d1=d1+30
    else:d=d1+31
    d=d1-d2
    m1=m1-1
if(m1>m2 or m1==m2):
    m=m1-m2
else:
    m1=m1+12
    m=m1-m2
    y1=y1-1
if(y1>y2 or y1==y2):
    y=y1-y2
print("   you are ",y,"years",m,"months",d,"days old")
print("\n   Made By Aakash Pramanik Of Class XI-B\n")





Question 16:- Write a program to input the year and check it is a leap year or not.
Answer:-
year=eval(input("\n\n   enter the year\n"))
if(year%4==0):
    print("  ",year,"is leapy year")
else:
    print("  ",year,"is not leapy year")
print("\n   Made By Aakash Pramanik Of Class XI-B\n")










Question 17:- Write a program to input the cost price and selling price of an item .find the transaction is profit , loss or no loss no profit and find the profit percent and loss percent.
Answer:-
cp=eval(input("\n\n   enter the cost price\n"))
sp=eval(input("   enter the selling price\n"))
if(sp>cp):
    print("   transaction is profit")
    pp=cp/sp*100
    print("   profit percentage is",round(pp,2))
elif(sp==cp):
    print("   no loss and no profit")
else:
    print("   transaction is loss")
    lp=sp/cp*100
    print("   lost percentage is",round(lp,2))
print("\n   Made By Aakash Pramanik Of Class XI-B\n")

Question 18:- Write a program to input 4 digit numbers to find greatest, smallest and second largest number.
Answer:-
big=0
a=b=0
small=100000
print("\n\n")
for i in range(1,4+1):
    print("   enter",i,"number")
    dig=eval(input())
    if(dig>a):
        b=a
        a=dig
    elif(dig>b):
        b=dig
    if(dig>big):
        big=dig
    if(small>dig):
        small=dig
print("   greatest number is",big)
print("   second largest number is",b)
print("   smallest number is",small)
print("\n   made By Aakash Pramanik Of Class XI-B\n")














Question 19:- The marks of 5 subjects of a student are input through keyboard the student get a division as per the following rule:
Greater than or equal to 60% :- 1st division
(50-59)% :- 2nd division
(40-49)% :- 3rddivision
Less than 40%:- 4th division
Write a program to calculate the division of student along report card and put the grade in each subject.
Greater than or equal to 60% :- A1
(50-59)% :- B1
(40-49)% :-C1
Less than 40%:-D1
Answer:-
a=eval(input("\n\n   enter the first subject marks\n"))
b=eval(input("   enter the second subject marks\n"))
c=eval(input("   enter the third subject marks\n"))
d=eval(input("   enter the fourth subject marks\n"))
e=eval(input("   enter the fifth subject marks\n"))
avg=(a+b+c+d+e)/5;
print("   average of the student is",avg)
if(avg>=60):
    print("   1st division")
    print("   Grade=A1")
elif(avg>=50 and avg<=59):
    print("   2nd devision")
    print("   Grade=B1")
elif(avg>=40 and avg<=49):
    print("   3rd devision")
    print("   Grade=C1")
elif(avg>=50 and avg<=59):
    print("   4th devision")
    print("   Grade=D1")
print("\n   Made By Aakash Pramanik Of Class XI-B\n")



Question 20:- Write a program to input any integer and check the integer is positive or negative or odd or even.
Answer:-
n=int(input("\n\n   enter the number\n"))
print("   number is",end=" ")
if(n>0):
    print("positive",end=",")
if(n<0):
    print("negative",end=",")
if(n%2==0):
    print("even",end=" ")
if(n%2!=0):
    print("odd",end=" ")
print("\n   Made By Aakash Pramanik Of Class XI-B\n")
           



Question 21:- Given 3 points (x1, y1), (x2, y2),(x3,y3). Check the given points are collinear or not.
Answer:-
x=eval(input("\n\n   enter the values of x\n"))
y=eval(input("   enter the values of y\n"))
x1=eval(input("   enter the values of x1\n"))
x2=eval(input("   enter the values of x2\n"))
y1=eval(input("   enter the values of y1\n"))
y2=eval(input("   enter the values of y2\n"))
s=(y2-y1)*x+(x1-x2)*y+(x2*y1-x1*y2)
if(s<0 or s>0):
    print("   points are not collinear")
else:
    print("   points are collinear")
print("\n   Made By Aakash Pramanik Of Class XI-B\n")




Question 22:- Write a program to find the point is lying in which quadrant.
Answer:-
c1=eval(input("\n\n   enter the first co-ordintes\n"))
c2=eval(input("   enter the second co-ordintes\n"))
if(c1>0 and c2>0):
    print("   point is lying in 1st quadrant")
elif(c1<0 and c2>0):
    print("   point is lying in 2nd quadrant")    
elif(c1<0 and c2<0):
     print("   point is lying in 3rd quadrant")
elif(c1>0 and c2<0):
     print("   point is lying in fourth quadrant")
elif(c1==0 and c2==0):
     print("   point is lying at the origin")
print("\n   Made By Aakash Pramanik Of Class XI-B\n")



Question 23:- Write a program to find the square roots of the quadratic equation ax2+bx+c=0, with all possible conditions.
Answer:-
import math
a=eval(input("\n\n   enter the first side\n"))
b=eval(input("   enter the second side\n"))
c=eval(input("   enter the third side\n"))
d=(b*b-4*a*c)
e=math.sqrt(d)
if(d<0):
    print("   roots are complex root")
elif(d>0):
    print("   roots are real and unequal")
    x1=(-b+e)/2
    x2=(-b-e)/2
    print("  ",round(x1,2))
    print("  ",round(x2,2))
elif(d==0):
    print("   roots are real and equal")
    x=-b/2
    print("  ",round(x,2))
    print("  ",round(x,2))
print("\n   Made By Aakash Pramanik Of Class XI-B\n")













Question 24:- Write a program to input 4 digit numbers. Check  the number is form palindrome or not (the reverse of the digit should be equal to original number)
Answer:-
num=int(input("\n\n   enter the four digit number\n"))
p=num
rev=0
for i in range(1,4+1):
          dig=num%10
          rev=rev*10+dig
          num=num//10
if(rev==p):
    print("   number is palindrome")
else:
    print("   number is not a palindrome")
print("\n   Made By Aakash Pramanik Of Class XI-B\n")
           


Question 25:- Write a program to input 3 digit numbers. Check that number is Armstrong number or not. (sum of the cube of the digit equal to the original number)
Answer:-
n=int(input("\n\n   enter the three digit number\n"))
a=n
sum=0
for i in range(1,3+1):
        dig=n%10
        sum=sum+dig*dig*dig
        n=n//10
if(sum==a):
    print("   number is armstrong")
else:
    print("   number is not a armstrong")
print("\n   Made By Aakash Pramanik Of Class XI-B\n")



Question 26:- Write a program to input 4 digit numbers. Check that the number is buzzle number or not. (if the number is divisible by 7 or 700).
Answer:-
n=eval(input("\n\n   enter the four digit number\n"))
if((n%7==0) or (n%700==0)):
    print("   buzzle number")
else:
    print("   not a buzzle number")
print("\n   Made By Aakash Pramanik Of Class XI-B\n")









Question 27:- Write a program to input 4 digit numbers. Check that the number is odd or even .if it is odd interchange the unit digit with thousand digit else interchange the tenth digit with hundredth digit.
Answer:-
n=eval(input("\n\n   enter the four digit number\n"))
if(n%2==0):
    n*=1000
else:
    n*=100
print("   now the number is",n)
print("\n   Made By Aakash Pramanik Of Class XI-B\n")







Question 28:- Write a program to find the sum of  n natural numbers by using:-
1. While loop                                    2.for loop
                                   

(1)              
Answer:-
n=eval(input("\n\n   enter the n\n"))
sum=0
i=0
while(i<=n):
    sum+=i
    i+=1
print("   sum of first",n,"natural numbers is",sum)
print("\n   Made By Aakash Pramanik Of Class XI-B\n")
                                           








(2)
Answer:-
n=eval(input("\n\n   enter the n\n"))
sum=0
for i in range(1,n+1):
    sum+=i
print("   sum of first",n,"natural numbers is",sum)
print("\n   Made By Aakash Pramanik Of Class XI-B\n")

   





Question 29:- Find the sum of odd natural numbers by using:-
1. While loop                                    2.for loop
                                      


          (1)
Answer:-
n=eval(input("\n\n   enter the n\n"))
sum=0
i=1
while(i<=n):
    sum+=i
    i+=2
print("   sum of first",n,"odd natural numbers is",sum)
print("\n   Made By Aakash Pramanik Of Class XI-B\n")








 (2)
Answer:-
n=eval(input("\n\n   enter the n\n"))
sum=0
for i in range(1,n+1,2):
    sum+=i
print("   sum of first",n,"odd natural numbers is",sum)
print("\n   Made By Aakash Pramanik Of Class XI-B\n")






Question 30:- Write a program to list the following from 100 to 500:-
1. Armstrong numbers
2.  palindrome numbers
3. Pythagoras triplets numbers
4. Buzzle  numbers
5. Reversing of numbers
6. Prime numbers
7. Composite numbers













(1)
Answer:-
print("\n\n")
for i in range(100,500+1):
    j=i
    sum=0
    while(i>0):
        dig=i%10
        sum=sum+dig*dig*dig
        i=i//10
    if(sum==j):
        print("  ",j,end=" ")
print("\n   Made By Aakash Pramanik Of Class XI-B\n")


                                        



(2)
Answer:-
print("\n\n")
for i in range(100,500+1):
    j=i
    rev=0
    while(i>0):
        dig=i%10
        rev=rev*10+dig
        i=i//10
    if(rev==j):
        print("    ",j,end="")
print("\n   Made By Aakash Pramanik Of Class XI-B\n")


          





(3)
Answer:-
print("\n\n")
for i in range(100,500+1):
    for j in range(100,500+1):
        for k in range(100,500+1):
            if((i*i + j*j)==k*k):
                print("    ",i,j,k,end="  , ")
print("\n   Made By Aakash Pramanik Of Class XI-B\n")












(4)
Answer:-
print("\n\n")
for i in range(100,500+1):
    if((i%7==0)or(i%700==0)):
        print(" ",i,end=",")
print("\n   Made By Aakash Pramanik Of Class XI-B\n")













(5)
Answer:-
print("\n\n")
for i in range(100,500+1):
    rev=0
    while(i>0):
        dig=i%10
        rev=rev*10+dig
        i=i//10
    print("    ",rev,end=",")
print("\n   Made By Aakash Pramanik Of Class XI-B\n")







(6)
Answer:-
print("\n\n")
for i in range(100,500+1):
    count=0
    for j in range(1,i+1):
        if(i%j==0):
            count+=1
    if(count==2):
        print("    ",i,end=",")
print("\n   Made By Aakash Pramanik Of Class XI-B\n")



   







(7)
Answer:-
print("\n\n")
for i in range(100,500+1):
    count=0
    for j in range(1,i+1):
        if(i%j==0):
            count+=1
    if(count>2):
            print("",i,end=",")
print("\n   Made By Aakash Pramanik Of Class XI-B\n")



Question 31:- Write a program to convert the following:-
1. Decimal to binary
2. Decimal to octal
3. Decimal to hexadecimal
(1)
Answer:-
bn=[]
i=0
dn=eval(input("\n\n   enter the decimal number\n"))
while(dn>=1):
    b=dn%2
    bn.insert(i,b)
    i+=1
    dn=dn//2
bn.reverse()
print("   binary form of the number is",bn)
print("\n   Made By Aakash Pramanik Of Class XI-B\n")



(2)
Answer:-
on=[]
i=0
dn=eval(input("\n\n   enter the decimal number\n"))
while(dn>=1):
    o=dn%8
    on.insert(i,o)
    i+=1
    dn=dn//8
on.reverse()
print("   octal form of the number is",on)
print("\n   Made By Aakash Pramanik Of Class XI-B\n")





(3)
Answer:-
hn=[]
i=0
dn=eval(input("\n\n   enter the decimal number\n"))
while(dn>=1):
    h=dn%16
    if(h<10):
        hn.insert(i,h)
    elif(h==10):
        hn.insert(i,'A')
    elif(h==11):
        hn.insert(i,'B')
    elif(h==12):
        hn.insert(i,'C')
    elif(h==13):
        hn.insert(i,'D')
    elif(h==14):
        hn.insert(i,'E')
    elif(h==15):
        hn.insert(i,'F')
    i+=1
    dn=dn//16
hn.reverse()
print("   hexadecimal  form of the number is",hn)
print("\n   Made By Aakash Pramanik Of Class XI-B\n")













Question 32:- Write a program to convert the following:-
1. Binary to decimal
2. Binaryto octal
3. Binary to hexadecimal

(1)
Answer:-
import math
bn=eval(input("\n\n   enter the binary number\n"))
p=0
dn=0
while(bn>=1):
    d=bn%10
    dn=dn+d*math.pow(2,p)
    p+=1
    bn=bn//10
print("   decimal form of the number is",int(dn))
print("\n   Made By Aakash Pramanik Of Class XI-B\n")


(2)
Answer:-
import math
bn=eval(input("\n\n   enter the binary number\n"))
p=0
dn=0
on=[]
i=0
while(bn>=1):
    d=bn%10
    dn=dn+d*math.pow(2,p)
    p+=1
    bn=bn//10
while(dn>=1):
    o=int(dn%8)
    on.insert(i,o)
    i+=1
    dn=dn//8
on.reverse()
print("   octal form of the number is",on)
print("\n   Made By Aakash Pramanik Of Class XI-B\n")


















(3)
Answer:-
import math
bn=eval(input("\n\n   enter the binary number\n"))
p=0
dn=0
hn=[]
i=0
while(bn>=1):
    d=bn%10
    dn=dn+d*math.pow(2,p)
    p+=1
    bn=bn//10
while(dn>=1):
    h=int(dn%16)
    if(h<10):
        hn.insert(i,h)
    elif(h==10):
        hn.insert(i,'A')
    elif(h==11):
        hn.insert(i,'B')
    elif(h==12):
        hn.insert(i,'C')
    elif(h==13):
        hn.insert(i,'D')
    elif(h==14):
        hn.insert(i,'E')
    elif(h==15):
        hn.insert(i,'F')
        i+=1
    dn=dn//16
print("   hexadecimal form of the number is",hn)
print("\n   Made By Aakash Pramanik Of Class XI-B\n")






Question 33:- Write a program to display a multiplication table each up to 10.
Answer:-
n=eval(input("\n\n   enter the number\n"))
for i in range(1,10+1):
    print("  ",n,"*",i,"=",n*i)
print("\n   Made By Aakash Pramanik Of Class XI-B\n")













Question 34:- Write a program to input the age and sex of n no. of students and find the average of each category.
Answer:-
n=eval(input("\n\n   enter the total number of students\n"))
boys=0
girls=0
for i in range(1,n+1):
    print("   enter age of",i,"student")
    age=int(input("   "))
    print("   enter sex of",i,"student (m/f)")
    sex=input("   ")
    if(sex=='m'):
        boys+=1
    else:
        girls+=1
print("   number of boys are",boys)
print("   number of girls are",girls)
boysavg=(boys*100)//n
girlsavg=(girls*100)//n
print("   boys average is",boysavg)
print("   girls average is",girlsavg)
print("   Made By Aakash Pramanik Of Class XI-B\n")
















Question 35:- Find the H.C.F and L.C.M of 2 numbers.
Answer:-
a=eval(input("\n\n   enter the first number\n"))
b=eval(input("   enter the second number\n"))
lcm=a*b
while(a!=b):
    if(a>b):
        a-=b
    else:
        b-=a
lcm//=a
print("   lcm of the numbers is",lcm)
print("   hcf of the numbers is",a)
print("\n   Made By Aakash Pramanik Of Class XI-B\n")





Question 36:- Write a program to display an alphabet A to Z and ascll code of each alphabet.
Answer:-
print("\n\n")
for i in range(65,90+1):
    ch=chr(i)
    print(ch,"=",i,end=",")
print("\n   Made By Aakash Pramanik Of Class XI-B\n")











Question 37:- Write a program to count the no. of digits in given number.
Answer:-
n=12345
count=0
while(n>0):
    n=n//10
    count+=1
print("\n\n   number of digits are",count)
print("\n   Made By Aakash Pramanik Of Class XI-B\n")










Question 39:- Write a program to input a number and find the no. of digit.
Answer:-
n=eval(input("\n\n   enter the number\n"))
count=0
while(n>0):
    n=n//10
    count+=1
print("   number of digits are",count)
print("\n   Made By Aakash Pramanik Of Class XI-B\n")










Question 40:- Write a program to input to
display the following program:-


(1)
Answer:-
print("\n\n")
for i in range(1,5+1):
        print("\n")
        for j in range(1,i+1):
                print("*",end="")
print("\n   Made By Aakash Pramanik Of Class XI-B\n")











(2)
Answer:-
print("\n\n")
for i in range(1,5+1):
        print("\n")
        for j in range(1,i+1):
                print("1",end="")
print("\n   Made By Aakash Pramanik Of Class XI-B\n")











(3)
Answer:-
print("\n\n")
for i in range(1,5+1):
        print("\n")
        for j in range(1,i+1):
                print(j,end="")
print("\n\n\nMade By Aakash Pramanik Of Class XI-B")



Python Programs 1


Q1. Program to find Greatest between two Numbers
a = int(input(“Enter 1st Number”))
b = (int(input(‘Enter 2nd Number’)))
if a>b :
        print (“%d is greater than %d ” % (a,b))
else :
        print (“%d is greater than %d ” % (b,a))
Q2. Program to check whether the given Year is  Leap Year.
year=int(input(“Enter Year”))
year=int(input(“Enter Year”))
if year%100 ==0 and year % 4==0 :
        print(“%d year is leap Year” %(year))
else :
         print(“%d year is not a leap Year” %(year))
Q3. Program to Calculate Grade 
s1 = int(input(“ENter Marks of 1st Subject”))
s2 = (int(input(‘ENter Marks of 2nd Subject’)))
s3 = (int(input(‘ENter Marks of 3rd Subject’)))
s4 = (int(input(‘ENter Marks of 4th Subject’)))
s5 = (int(input(‘ENter Marks of 5th Subject’)))
total =s1 +s2 +s3 +s4 +s5
per =total/5
print (“\n\n Grade = “,end=”)
if per>=90 :
      print(“A”)
elif per> 60 :
    print (“B”)
elif per> 45 :
    print (“C”)
elif per> 33 :
    print (“D”)
else :
    print (“E”)
Q4. Program to find greatest among Three Numbers
a = int(input(“ENter 1st Number”))
b = (int(input(‘ENter 2nd Number’)))
c = int(input(“ENter 3rd Number”))
if a>b :
    if a>c:
            print (“%d is greatest ” % (a))
   else :
            print (“%d is greatest” % (c))
   else :
       if b>c :
             print (“%d is greatest” % (b))
      else :
              print (“%d is greatest” % (c))
Q5. Program to check whether the no. is Even or Odd.
a=int(input(‘Enter a Number’)
if (a%2==0):
print(a, “is an Even Number”)
else: 
     print(a, “is an Odd Number”)
1. Program to print Even  Numbers up to N
N=int(input(“enter number “))
for i in range(2,N,2):
print(i,end=” “)
Q2. Program to print Fibonacci Series 0,1,1,2,3,5,8,13…….
no1=1
no2=2
print(” ,+ no1)
print(‘\n’,+no2)
x=1
while(x<=10):
no3=no1+no2
no1=no2
no2=no3
no2=no3
print (‘\n’,+no3)
x=x+1
Q3 Program to print First 10 Natural Numbers
print (‘First 10 Natural Numbers are ‘)
for i in range(1,11) :
print (i)
Q4, Program to print Multiplication Table of a Given Numbers
a=int(input(‘Enter a Number’))
i=1
while i<=10:
t=a*i
print (“%d X %d = %d ” % (a,i,t))
i=i+1
Q5 Program to check whether the given no. is Prime or not (Method I)
no=int(input(“Enter Number : “))
for i in range(2,no):
      ans=no%i
      if ans==0:
           print (‘Non Prime’)
           break
     elif i==no-1:
            print(‘Prime Number’)
(II Method)
n=int(input(“enter
n=int(input(“enter the no “))
f=0
if n==1 or n==0 :
print(“No is not complex nor composite”)
elif n>=2 :
for i in range(2, (n+1)/2):
if n%i==0 :
f=1
break
if f==0 :
print(“It is Prime Number”)
else :
print(“it is not a Prime Number”)
Q6. Program to Calculate Factorial of a given Number
a=int(input(‘Enter a Number to calculate factorial’))
f=1
while (a> 1):
    f=f*a
    a=a – 1
print (‘FActorial is %d’%(f))
Q7. Program to print First 10 Natural Numbers in reverse Order.
print (‘First 10 Natural Numbers are ‘)
for i in range(10,0,-1) :
     print (i)
Q8. Write a Program to find smallest among given numbers
sm=int(input(‘Enter :’))
for i in range ( 1,10):
      n=int(input(‘Enter :’))
      if n<sm:
          sm=n
print (“Smallest number is %d” % (sm))
Q9 Program to check whether the given number is an Armstrong Number
no=int(input(“Enter any number to check : “))
no1 = no
sum = 0
while(no>0):
     ans = no % 10;
sum = sum + (ans * ans * ans)
     no = int (no / 10)
 if sum == no1:
      print(“Armstrong Number”)
else:
       print(“Not an Armstrong Number”)
Q10 Prpgram to print series of Prime Numbers between 1 to 100
for i in range(1,101):
       for j in range(2, i):
            ans = i % j
            if ans==0:
                print (i,end=’ ‘)
                 break
11. Program to print Odd  Numbers up to N
N=int(input(“enter number “))
for i in range(1,N,2):
print(i,end=” “)
12.PROGRAM TO PRINT SERIES 1 4 7 10 13…….N
n=int(input(“enter the number “))
for i in range(1, n+1, 3):
print(i,end=” “)
13.PROGRAM TO CALCULATE X TO THE POWER Y
x=int(input(“enter the no “))
y=int(input(“enter the no “))
p=1
for i in range(1, y+1):
p*=x
print(p)
14 PROGRAM TO CALULATE LCM AND GCD
n1=int(input(“enter the no “))
n2=int(input(“enter the no “))
gcd=lcm=r=n=d=0
if n1>n2 :
n=n1
d=n2
else :
n=n2
d=n1
r=n%d
while r!=0 :
n=d
d=r
r=n%d
gcd=d
lcm=n1*n2/gcd
print((“GCD of %d and %d=%d\n”)%(n1,n2,gcd))
print((“LCM of %d and %d=%d\n”)%(n1,n2,lcm))

1. write a program to read text and count total no. of lower case letters upper Case letters, digits,alphabets, special characters, Total Words .

text=input(“Enter Text”)
l=u=d=a=s=sp=0
for ch in text:
if ch.isalpha():
a+=1
if ch.islower():
l+=1
elif ch.isupper():
u+=1
elif ch.isdigit():
d+=1
elif ch.isspace():
sp+=1
else:
s+=1
print(‘Total Alphabets are :’,a)
print(‘Total Upper Case are :’,u)
print(‘Total Lower Case are :’,l)
print(‘Total Digits are :’,d)
print(‘Total Special Characters :’,s)
print(‘Total WORDS ARE :’,sp+1)

2. write a program to read text and capitalize first letter of each word

text=input(“Enter Text”)
L=[]
NW=””
L=text.split()
for ch in L:
NW+=ch.capitalize()+’ ‘
print(NW)

3. write a program to find sub string in a text given

text=input(“Enter Text”)
sub=input(“Enter sub string to find in Text”)
f=text.find(sub)
if f==-1:
print(sub,’ is not present ‘)
else:
print(sub,’ is present at ‘,f,’ position’)

4. write a program to check whether the given string is palindrome

str=input(“Enter Text”)
rev=str[::-1]
if str==rev:
print(str, ‘ is Palindrome’)
else:
print(str, ‘ is not Palindrome’)
Q1 Write a Python program to get the smallest number from a list
Items=list(input(“Enter List Elements “))
min = list[ 0 ]
for a in list:
     if a < min:
         min = a

print(“Minimum NO. IN LIST “,max)
Q2 Write a Python program to sum all the items in a list.
Items=list(input(“Enter ListElements “))
    sum_numbers = 0
    for x in items:
        sum_numbers += x
print(sum_list([1,2,-8]))
Q3 Write a Python program to get the largest number from a list.
Items=list(input(“Enter List Elements “))
max = list[ 0 ]
for a in list:
    if a > max:
        max = a
print(“MAXIMUM NO. IN LIST “,max)
Q4. Write a Python program to remove duplicates from a list
a = [10,20,30,20,10,50,60,40,80,50,40]
dup_items = set()
uniq_items = []
for x in a:
    if x not in dup_items:
        uniq_items.append(x)
        dup_items.add(x)
print(dup_items)
Q5.Write a Python program to check a list is empty or not
l = []
if not l:
     print(“List is empty”)
Q6.
“”” Program to count numbers in a List”””
x = [4, 7, 9, 12, 10]
count = 0 for i in x:
count= count + 1
print(“Total number of elements = “, count)

7.

“”” Program to find average of numbers in a List”””
A = [6, 2, 7, 9, 1, 3]
Sum = 0
Avg = 0
for x in range(len(A)): Sum += A[x];
Avg = Sum/len(A); print(“Average = “, Avg)

8.

“” Program to find maximum among N numbers in a List”””
x = []
N = eval(input(“entersize of list : “)) for i in range(0, N):
x.append(eval(input(“enter”+ str(i) + ” element : “))) print(“Numbers in the list are “)
print(x)
max = x[0]
for i in range(1, N):
if ( x[i] > max): max = x[i]
print(“Maximum value in the list = “, max)

9.

“” Program to find minimum among N numbers in a List”””
x = []
N = eval(input(“entersize of list : “)) for i in range(N):
·         append(eval(input(“enter”+ str(i) + ” element : “))) print(“Numbers in the list are “)
print(x)
min = x[0]
for i in range(1, N):
if ( x[i] < min): min = x[i]
print(“Minimum value in the list = “, min)

10.

“”” Program to search a number in the list (Linear Search) “””
A=[]
N=eval(input(“entertotal numbers to be entered”)) for i in range(0,N):
A.append(eval(input(“Enter”+str(i)+”Element”)))
s=eval(input(“enterelement to be searched”)) found=-1
for i in range(0,N):
if (s==A[i]):
found=i
if (found!=-1):
print(“element found at position”,found) else:
print(“element not found”)

11.

“”” Program to arrange numbers in ascending order using Bubble Sort Method”””
x = []
N = eval(input(“entersize of list : “)) for i in range(0, N):
x.append(eval(input(“enter”+ str(i) + ” element : “))) print(x)
count = 0
for i in range(0, N-1):
for j in range(0, N-i-1): if x[j] > x[j+1]:
t = x[j]
x[j] = x[j+1] x[j+1] = t
count = count + 1 print(“Pass”,i+1,”:”, x)
print(“Total number of operations = “, count)
print(“Elements in ascending order are : \n”, x)

12. “”” Program to arrange numbers in ascending order using Insertion Sort Method”””

x = []
N = eval(input(“entersize of list : “)) for i in range(0, N):
x.append(eval(input(“enter”+ str(i) + ” element : “))) print(“List with original elements :\n”,x)
#we assume that smallest element at first index i.e. 0
for i in range(2, N): t = x[i]
k = i-1
while t < x[k]: x[k+1] = x[k] k = k – 1
x[k+1] = t
print(“Sorted List in ascending order :\n”,x)

13.

“”” Program to arrange numbers in ascending order using Selection Sort Method”””
x = []
N = eval(input(“entersize of list : “)) for i in range(0, N):
x.append(eval(input(“enter”+ str(i) + ” element : “))) print(x)
count = 0
for i in range(0, N-1):
for j in range(i+1, N): if x[i] > x[j]:
t = x[i] x[i] = x[j] x[j] = t
count = count + 1 print(“Pass”,i+1,”:”, x)
print(“Total number of operations = “, count)
print(“Elements in ascending order are : \n”, x)

14. Program to read a list and print only those numbrs which are divisible by 5 and not by 7

num=list(eval((input(“Enter numbers “))))
for i in num:
if (i%5==0 and i%7 !=0):
print (i,”is divisable by 5 but not by 7″)
15. Program to read String and check whether it is palindrome using list
msg=input(“Enter any string : “)
newlist=[]
newlist[:0]=msg
l=len(newlist)
last=l-1
for i in range(0,l):
if newlist[i]!=newlist[last]:
print (“Given String is not a palindrome”)
break
if i>=last:
print (“Given String is a palindrome”)
break
l=l-1
last = last- 1

Programs Using Pandas

Q Write a program to create dataframe for 3 student including name and roll numbers. and add new columns for 5 subjects and 1 column to calculate percentage. It should include random numbers in marks of all subjects
import pandas as pd, numpy as np, random
D={‘Roll’:[1,2,3],’Name’:[‘Sangeeta’,’Shanti’,’Swati’]}
P=[]
C=[]
M=[]
E=[]
H=[]
SD=pd.DataFrame(D)
for i in range(3):
P.append(random.randint(1,101))
C.append(random.randint(1,101))
M.append(random.randint(1,101))
E.append(random.randint(1,101))
H.append(random.randint(1,101))
SD[‘Phy’]=P
SD[‘Chem’]=C
SD[‘Maths’]=M
SD[‘Eng’]=E
SD[‘Hin’]=H
SD[‘Total’]=SD.Phy+SD.Chem+SD.Maths+SD.Eng+SD.Hin
SD[‘Per’]=SD.Total/5
Print(SD)

File Handling

1 Program to Generate Factorial from 1 to 10 and write it into file fact_till_10

file=open(‘fact_till_10.txt’,’w’)
for i in range(0,11):
f=1
for j in range (i,0,-1):
f=f*j
file.write(‘\n factorial of ‘ + str(i) +’ is ‘ + str(f))
file.close()
2. Program to find the word “This” in the myfile.py 
and display line no. in which the given word is found
f=open(“myfile.py”,”r”)
word=”This”
c=0
for i in f.readlines():
c+=1
if word in i.split():
print(“found at ” +str(c))
f.close()

3. Program to Copy an existing file to a new file

f1=open(“myfile.py”,”r”)
f2=open(“myNwfile.py”,”w”)
x=f1.read()
f2.write(x)
f1.close()
f2.close()

4. Program to count Total no. of lines present in the given file

FileName=input(‘Enter Name of File’)
File=open(FileName)
print(‘Total Number of lines in’,FileName,’are’,str(len(File.readlines())))

5. Program to read a list and print only those numbrs in file which are divisible by 5 and not by 7

f=open(“MyNum.py”,”w”)
num=list(eval((input(“Enter numbers “))))
for i in num:
if (i%5==0 and i%7 !=0):
f.write(str(i) + ” is divisable by 5 but not by 7\n”)
f.close()
___________________________________________________