Friday, November 27, 2020

Python Programs for Standard XI

All these programs has to be written in Theory note book(Both side ruled)

Students are advised to copy all the programs from the site

Every week new programs will be added

Sequence Structure Programming


1. Write a program to perform all the arithmetic operation with two variables

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

b=int(input("Enter b"))

c=a+b

d=a-b

e=a*b

f=a/b

g=a%b

print("Sum ",c)

print("Difference ",d)

print("Product ",e)

print("Division ",f)

print("Modulus ",g)


2. Write a program to Calculate the Area and Perimeter of the Rectagle

l=int(input("Enter Length"))

b=int(input("Enter Breadth"))

a=l*b

p=2*l+b

print("Area ",a)

print("Perimeter ",p)

 

3. Write a program to calculate the Area and Circumference of the Circle

r=int(input("Enter Radius"))

a=3.142*r*r

c=2*3.142*r

print("Area ",a)

print("Circumference ",c)

 

4. Write a Program to Accept the time in seconds and display it in minute and seconds

s=int(input("Enter Time"))

m=s//60

rs=s%60

print("Minute ",m)

print("Remaining seconds ",rs)


5. Write a program to Accept the time in seconds and display it in hour, minute and seconds

s=int(input("Enter Time"))

h=s//3600

rs=s%3600

m=rs//60)

rs=s%60

print("Hour ",h)

print("Minute ",m)

print("Remaining seconds ",rs)


6. Write a program to Find the absolute, integer, float, round, minimum, maximum of a given number

n=float(input("Enter Number"))

print("Absolute ",abs(n))

print("Integer ",int(n))

print("float",float(n))

print("round",round(n,1))

print("minimum",min(n,123,12))

print("maximum",max(n,123,12))

 

7. Write a program to use all standard Mathematical Functions of Python

import math

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

print("Square Root ",math.sqrt(n))

print("e raised a power  ",math.exp(n))

print("Natural Logarithm  ",math.log(n))

print("Common Logarithm ",math.log10(n))

print("Square  ",math.pow(n,2))

print("Cube  ",math.pow(n,3))

print("Degrees  ",math.degrees(math.pi/180))

print("Radians  ",math.radians(180/math.pi*30))

print("Absolute value  ",math.fabs(n))


Selection Structure Programming


8. Accept the age from the user and check whether he is eligible to vote or not

a=int(input("Enter Age"))

if a>=18 :

    print("Eligible to vote")

else :

    print("Not Eligible to vote")


9. Accept a number and Check whether the number is odd or even

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

if n%2==0 :

    print("Even");

else :

    print("Odd");


10. Accept a number and Check whether the number is divisible by 5 or not

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

if n%5==0 :

    print("Divisible by 5")

else :

    print("Not divisible by 5")


11. Accept a number and Check whether the number is a Buzz number or Not

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

if n%7==0 or n%10==7 :

    print("Buzz Number")

else :

    print("Not Buzz Number")


12. Accept a number and Check whether the number is a negative number, zero, positive number

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

if n<0 :

    print("Negative Number")

elif n==0 :

    print("Zero Number")

else :

    print("Positive Number")


13. Accept the sides of a triangle and find the greatest side

a=int(input("Enter Side"))

b=int(input("Enter Side"))

c=int(input("Enter Side"))

if a>b and a>c :

    print("A is the Greatest Side")

elif b>c and b>a :

    print("B is the Greatest Side")

else :

    print("C is the Greatest Side")


14. Accept sides of a triangle and check whether it is Equilateral, Isosceles, and Scalene Triangle

a=int(input("Enter Side"))

b=int(input("Enter Side"))

c=int(input("Enter Side"))

if a==b and a==c and b==c :

    print("Equilateral Triangle")

elif a==b or b==c or c==a :

    print("Isoceles Triangle")

else :

    print("Scalene Triangle")


15. Accept three marks of a student. If average >= 40 declare Pass else Fail.

m1=int(input("Enter Mark1"))

m2=int(input("Enter Mark2"))

m3=int(input("Enter Mark3"))

av=(m1+m2+m3)/3

if av>=40:

    print("Pass")

else:

    print("Fail")


16. Accept three marks of a student and find out whether the student has passed or failed. If the individual mark is less than 40 declare fail. If average>=80 display Grade A if average>=60 display Grade B else Grade C

a=int(input("Enter Mark of First Subject"))

b=int(input("Enter Mark of Second Subject"))

c=int(input("Enter Mark of Third Subject"))

if a<40 or b<40 or c<40 :

    print("Student has failed")

elif (a+b+c)/3 >80 :

    print("Grade A")

elif (a+b+c)/3 >60 :

    print("Grade B")

else :

    print("Grade C")


17. Accept three numbers of a quadratic equation and find the nature of the Roots

a=int(input("Enter Number"))

b=int(input("Enter Number"))

c=int(input("Enter Number"))

if (a*b*b - 4*a*c) ==0 :

    print("real and equal")

elif (a*b*b - 4*a*c) >0  :

    print("real and non-zero")

else :

    print("not real")


18. Accept cost & selling price and check whether he has made profit, loss, no profit no loss.

cp=int(input("Enter Cost Price"))

sp=int(input("Enter Selling Price"))

if sp>cp:

    print("Profit")

elif cp>sp:

    print("Loss")

else:

    print("No Profit No Loss")


19. Accept a year and check whether it is a leap year or not.

y=int(input("Enter Year"))

if y%100==0:

    if y%400==0:

        print("Leap Year")

    else:

        print("Not Leap Year")

else:

    if y%4==0:

        print("Leap Year")

    else:

        print("Not Leap Year")


20. Accept three marks of a student. If any subject mark<40 declare Fail else Pass

m1=int(input("Enter Mark1"))

m2=int(input("Enter Mark2"))

m3=int(input("Enter Mark3"))

if m1<40 or m2<40 or m3<40:

    print("Fail")

else:

    print("Pass")


21. To calculate discount on the cost of purchased items, based on the following criteria

Cost                 Discount(In percentage)

Less than or equal to ₹ 10000         5 %

More than ₹ 10000 and less than or equal to ₹ 20000 10 %

More than ₹ 20000 and less than or equal to ₹ 35000                15 %

More than ₹ 35000         20%

cp=int(input("Enter the Cost Price"))

if cp<=10000:

dis = cp * 5/100

elif cp<=20000:

dis = cp * 10/100

elif cp<=35000:

dis = cp * 15/100

else :

dis = cp * 20/100

amount = cp - dis

print("The Selling Price after discount", amount)


22. Write a program to compute the tax according to the given conditions and display the output as per given format.     

Total annual Taxable Income Tax Rate

Upto Rs. 1,00;000 No tax

From 1,00,001 to 1,50,000 10% of the income exceeding Rs. 1,00,000

From 1,50,001 to 2,50,000 Rs. 5,000 + 20% of the income exceeding Rs. 1,50,000

Above Rs. 2,50,000 Rs. 25,000 + 30% of the income exceeding Rs. 2,50,000.

taxincome=int(input("Enter the Taxable Amount"))

if taxincome<=100000 :

        tax=0.0

elif taxincome<=150000 :

        tax=.1*(taxincome-100000)

elif taxincome<=250000 :

        tax=5000 + .2*(taxincome-150000)

else :

        tax=25000 + .3*(taxincome-250000)

print("Tax to be paid = Rs.",tax)


23. The telephone department wishes to compute monthly telephone bills for its customers using the following rules. Minimum Rs. 250 for first 80 message units, plus 60 paisa per unit for next 60 units, plus 50 paisa per unit for next 60 units, plus 40 paisa per unit for any units above 200. Write a program that calculates the monthly bill, with input MESSAGE (the number of message units) and CUSTNO (the registration number of a customer). Then Display the bill in following format.

CUSTOMER NO :

MESSAGE UNITS :

AMOUNT (Rs.) :

customerNo=int(input("Enter Customer Number"))

Unit=int(input("Enter units"))

if Unit<= 80 :

      bill = 250

elif Unit>80 and Unit<= 140 :

      bill = 250+(Unit-80)*0.60

elif Unit>140 and Unit<= 200 :

      bill = 250+36+(Unit-140)*0.50

elif Unit>200 :

      bill = 250+36+30+(Unit-200)*0.40

print ("CUSTOMER NUMBER : ",customerNo)

print ("MESSAGE UNIT : ",Unit)

print ("BILL AMOUNT : ",bill)


24. A computer salesman gets commission on the following basis:

Sales                        Commission Rate

Rs. 0 - 20,000                5%

Rs. 20,000 - 50,000          10%

Rs. 50,001 and more          20%

After accepting the sales as input, calculate and print his commission amount and rate of commission.

sales=int(input("Enter Sales"))

if sales <= 20000:

      rate = 5

      commission = sales*.05

if sales> = 20001 and sales <= 50000:

      rate = 10

      commission = sales*.10

if sales> = 50001 

      rate = 20

      commission = sales*.20

print("Commission Rate : ",rate,"%") 

print("Commission Amount : ",commission)


25. Arithmetic menu driven Program.

print("1. Add two Numbers")

print("2. Subtract two Numbers")

print("3. Product two Numbers")

ch=int(input("Enter your choice"))

a=int(input("Enter A"))

b=int(input("Enter B"))

if ch==1:

    print("Sum ",(a+b))

if ch==2:

    print("Difference ",(a-b))

if ch==3:

    print("Product ",(a*b))


26. Area menu driven Program.

print("1. Area of Square")

print("2. Area of Circle")

print("3. Area or Rectangle")

ch=int(input("Enter your choice"))

if ch==1:

    s=int(input("Enter Side"))

    a=s*s

    print("Area of Square ",a)

if ch==2:

    r=int(input("Enter Radius"))

    a=3.142*r*r

    print("Area of Circle ",a)

if ch==3:

    l=int(input("Enter Length"))

    b=int(input("Enter breadth"))

    a=l*b

    print("Area of Square ",a)



27. Generate natural numbers from 1 to 10
ser=[1,2,3,4,5,6,7,8,9,10]
for i in ser:
    print(i)

28. Generate even numbers from 2 to 10
ser=[2,4,6,8,10]
for i in ser:
    print(i)

29. Generate natural numbers from 1 to 10
for i in range(1, 10):
    print(i)

30. Generate natural number from 1 to 10
i=1
while i<=10 :
    print(i)
    i=i+1

31. Generate odd numbers from 1 to 10
i=1
while i<=10 :
    print(i)
    i+=2
 
32. Generate even numbers from 2 to 10
i=2
while i<=10 :
    print(i)
    i+=2

33. Generate even numbers from 2 to 10
i=1
while i<=10 :
    if i % 2==0 :
        print(i)
    i=i+1

34. Generate multiplication table of any given number 
n=int(input("Enter Number"))
i=1
while i<=10 :
    print(n,'*',i,'=',n*i)
    i=i+1

35. Factors :- The numbers that are completely divisible by the given value (it means the remainder should be 0) called as factors of a given number.
Display the Factors of a given number
n=int(input("Enter number"))   
for i in range(1,n+1,1):
    if n%i == 0 :
       print(i,end=",")

36. Prime :- Prime numbers are the numbers with two factors, 1 and the number itself. It can be divided evenly by the two factors.
Check whether a given number is prime or not
c=0   
n=int(input("Enter number"))   
for i in range(1,n+1,1):
    if n%i == 0 :
        c=c+1
    if c==2 :
        print("Prime")   
    else :
        print("Not Prime")

37. Twin Prime :- Both the numbers has two factors and the difference between the two prime numbers is two.
Accept two numbers and check whether they are twin prime or not
c1=0   
c2=0
m=int(input("Enter First number"))   
n=int(input("Enter Second number"))   
for i in range(1,m+1,1):
    if m%i == 0 :
       c1=c1+1   
for i in range(1,n+1,1):
    if n%i == 0 :
       c2=c2+1   
if c1==2 and c2==2 and abs(m-n)==2:
        print("Twin Prime")   
else :
        print("Not Twin Prime")

38. HCF and LCM :- HCF : The largest number that divides two or more numbers is the highest common factor (HCF) for those numbers. LCM : The least number which is exactly divisible by each of the given numbers is called the least common multiple of those numbers.
Find the HCF and LCM of two given numbers
m=int(input("Enter First number"))   
n=int(input("Enter Second number"))   
for i in range(1,m+1,1):
    if m%i == 0 and n%i == 0:
            hcf=i
lcm=m*n/hcf   
print("HCF ",hcf)   
print("LCM ",lcm)

39. Sum of Individual Digit :- The sum of digits allows the user to enter any positive integer. Then the program will divide the given number into individual digits and adding those individual digits.
Display the Sum of the digits of a given number   
s=0
n=int(input("Enter number"))   
while n>0 :       
 j=n%10       
 s=s+j       
 n=n//10
print("Sum of Digits ",s)

40. Palindrome Number :-A palindromic number is a number that remains the same when its digits are reversed. The term palindromic is derived from palindrome, which refers to a word whose spelling is unchanged when its letters are reversed.
Check whether the Given number is Palindrome or not
s=0
n=int(input("Enter number"))
m=n   
while n>0 :
         j=n%10
         s=s*10+j
         n=n//10   
if(m==s):
        print("Palindrome Number")   
else :
        print("Not Palindrome Number")

41. Armstrong Number :- Armstrong number in a given number base is a number that is the sum of its own digits each raised to the power of three of digits.
Check whether the given number is armstrong number or not
s=0
n=int(input("Enter number"))
m=n   
while n>0 :
         j=n%10
         s=s+j**3
         n=n//10   
if(m==s):
         print("Armstrong Number")
else :
         print("Not Armstrong Number")

42. Neon Number :- A neon number is a number where the sum of digits of square of the number is equal to the number.
Check whether the given number is neon or not
s=0
n=int(input("Enter number"))   
m=n*n   
while m>0 :
         j=m%10
         s=s+j
         m=m//10
if(n==s):
         print("Neon Number")   
else :
         print("Not Neon Number")

43. Spy Number :- A spy number is a number where the sum of its digits equals the product of its digits.
Check whether the given number is a Spy number or Not
s=0   
p=1   
n=int(input("Enter number"))
while n>0 :
         j=n%10
         s=s+j
         p=p*j
         n=n//10
if(p==s):
         print("Spy Number")
else :
         print("Not Spy Number")

44. Niven Number :- An integer number in base 10 which is divisible by sum of it digits is known as the niven number.
Check whether the given number is a Niven number or not
s=0
n=int(input("Enter number"))
m=n   
while m>0 :
         j=m%10
         s=s+j
         m=m//10
if(n%s==0):
        print("Niven Number")   
else :
        print("Not Niven Number")

45. Accept six elements in the list and display the first three element of the list.
list=[]
for i in range(6):
    list.append(input("Enter no :-"))
for i in range(3):
    print(list[i])

46. Accept six elements in the list and display the last three element of the list.
list=[]
for i in range(6):
    list.append(input("Enter no :-"))
for i in range(5,2,-1):
    print(list[i])

47. Sum of all the elements accepted in a list. The size of the list is six.
s=0
list=[]
for i in range(6):
    list.append(int(input("Enter no :-")))
for i in range(6):
    s=s+list[i]
print("Sum of Array elements ",s)

48. Sum of Odd and Even elements present in the List. The size of the list is six.
s1=s2=0
list=[]
for i in range(6):
    list.append(int(input("Enter no :-")))
for i in range(6):
    if list[i]%2 == 0 :
        s1=s1+list[i]
    else :
        s2=s2+list[i]
print("Sum of Even elem ",s1)
print("Sum of Odd elem ",s2)

49. Sum of Odd and Even position present in the List. The size of the list is six.
s1=s2=0
list=[]
for i in range(6):
    list.append(int(input("Enter no :-")))
for i in range(6):
    if i%2 == 0 :
        s1=s1+list[i]
    else :
        s2=s2+list[i]
print("Sum - Even position ",s1)
print("Sum - Odd position ",s2)

50. Accept six elements in the list and a search element form the user and find whether the element is present in the list by linear search method.
c=0
list=[]
for i in range(6):
    list.append(int(input("Enter no :-")))
se=int(input("Search Element"))
for i in range(6) :
    if list[i] == se :
        c=c+1
if(c>0):
    print("Search Found ")
else :
    print("Search Not Found ")

51. Accept six elements in the list and a search element form the user and find whether the element is present in the list by binary search method.
c=0
list=[]
for i in range(6):
    list.append(int(input("Enter no :-")))
se=int(input("Search Element"))
l=0
h=5
while l<=h:
    m=(l+h)//2
    if list[m] == se :
        c=c+1
        break;
    if list[m] < se :
        l=m+1
    if list[m] > se :
        h=m-1
if(c>0):
    print("Search Found ")
else :
    print("Search Not Found ")

52. Find the frequency of the given number in the list.
list=[]
for i in range(6):
    list.append(input("Enter no :-"))
se=input("Enter Search Element")
for i in range(6):
    if se==list[i]:
        print("Position of Element",i)

53. Accept six elements in the list and sort the elements in ascending order by bubble sort method.
list=[]
for i in range(6):
    list.append(int(input("Enter no :-")))
print("Org Lst",list)
for i in range(5):
    for j in range(0,6-i-1,1):
        if list[j]>list[j+1]:
            t=list[j]
            list[j]=list[j+1]
            list[j+1]=t
print("Sorted Lst",list)

54. Accept six elements in the list and sort the elements in descending order by bubble sort method.
list=[]
for i in range(6):
    list.append(int(input("Enter no :-")))
print("Org Lst",list)
for i in range(5):
    for j in range(0,6-i-1,1):
        if list[j]<list[j+1]:
            t=list[j]
            list[j]=list[j+1]
            list[j+1]=t
print("Sorted Lst",list)

55. Accept three elements in listA and three elements in listB and merge them to a single list.
list1=[]
list2=[]
list3=[]
for i in range(3):
    list1.append(int(input("Enter no :-")))
for i in range(3):
    list2.append(int(input("Enter no :-")))
list3=list1+list2
print(list3)

56. Count the numeric and alphabets present in a given word or sentence.
s=input("Enter String")
c=0
a=0
for i in range(len(s)) :
    if s[i].isalpha() :
        a=a+1
    if s[i].isnumeric() :
        c=c+1
print("Number of Alphabets",a)
print("Number of Numeric",c)

57. Count the number of alphabets, digits, spaces and alphabet and number both
s=input("Enter String")
l=a=p=d=0
for i in range(len(s)) :
    if s[i].isalnum() :
        a=a+1
    if s[i].isdigit() :
        d=d+1
    if s[i].isalpha() :
        l=l+1
    if s[i].isspace() :
        p=p+1
print("Number of Alphabets or Numbers",a)
print("Number of Digits",d)
print("Number of Alphabets",l)
print("Number of Spaces",p)

58. Count the number of words in a given sentence.
s=input("Enter String")
c=0
for i in range(len(s)) :
    if s[i].isspace() :
        c=c+1
print("Number of words",c)

59. Accept the file name along with drive and path and display the drive, path name, file name and Extension
s="C:/user/Admin/Flowers.jpg"
x=s.index('/')
y=s.rindex('/')
z=s.index('.')
m=len(s)
print("Drive ",s[0:x])
print("Path ",s[x+1:y])
print("File Name ",s[y+1:z])
print("Extension ",s[z+1:m])

60. Accept a sentence and count the number of alphabets,digits and special symbols.
a=d=s=0
str = "C++ was an old language till 2020 for CBSE"
for i in range(len(str)):
    if str[i].isalpha():
        a=a+1
    if str[i].isdigit():
        d=d+1
    if not(str[i].isalnum() or str[i].isdigit() or str[i].isspace()):
        s=s+1
print("Alphabet ",a)
print("Digit ",d)
print("Special Symbol ",s)