Computer
Science
Practical
File
Class: XI A
Name: Mehul Goel
Index
S.NO. PROGRAM LIST SIGN
1. Program list 1
2. Program List 2
3. Loop Questions
4. Program List-3
Program List-1
Q1.WAP to display all keywords.
Program:
import keyword
print(keyword.kwlist)
Q2.WAP to input to numbers and find their sum and product.
Program:
a=float(input("Enter First Number"))
b=float(input("Enter Second Number"))
c=a*b
d=a+b
print("Sum of two number",d)
print("Product of two number",c)
Q3.WAP to calculate SI by inputting value of principal amount and rate from
the user for a time period of 5 years.
Program:
a=float(input("Enter Principal Amount"))
b=float(input("Enter Rate of Intrest"))
c=5
d=(a*b*c)/100
print("Simple Intrest on time period of 5 years",d)
Q4.WAP to calculate area of triangle by inputting valur of base and height of
the triangle.
Program:
a=float(input("Enter Height of Triangle"))
b=float(input("Enter Base of Triangle"))
c=1/2*a*b
print("Area of Triangle=",c)
Q5.WAP to to accept radius of a circle and print its area.
Program:
a=float(input("Enter radius of circle"))
b=22/7*(a**2)
print("Area of Circle",b)
Q6.WAP to accept marks in 5 subjecs and display the average marks.
Program:
a=float(input("Enter English Marks"))
b=float(input("Enter Maths Marks"))
c=float(input("Enter Physics Marks"))
d=float(input("Enter Chemistry Marks"))
e=float(input("Enter CS Marks"))
F=(a+b+c+d+e)/5
print("Average Marks",F)
Q7.WAP to convert km to miles.
Program:
a=float(input("Enter Distance in kilometres"))
b=a*0.621
print("Distance in miles",b)
Q8.WAP to convert Celsius to farehnite.
Program:
a=float(input("Enter temprature in Celsius"))
b=a+(9/5)+32
print("Temprature in Farehnite",b)
Q9.WAP to accept length and breath and display the area and perimeter of a
triangle.
Program:
a=float(input("Length of Rect-"))
b=float(input("Breath of Rect-"))
c=a*b
print("area of rectangle",c)
d=2*(a+b)
print("perimetre of rectangle",d)
Q10.WAP to accept length and display the area and perimeter of the square.
Program:
s=float(input("Enter the side-"))
a=s*s
print("area of square=",a)
p=4*s
print("Perimeter of Square",p)
Q11.WAP to input its number and print its first five multiples.
Program:
a=float(input("Enter Number"))
b=a*1
c=a*2
d=a*3
e=a*4
f=a*5
print("First five multiples of number",b,c,d,e,f)
Q12.WAP to input a number and print its first five multiples.
Program:
a=float(input("Enter Fee Amount"))
b=((10/100)*a)+a
print("Fee amount after hike",b)
Q13. WAP to enter a sall poem or poem vere and print it.
Program:
a=input("Enter Poem")
print(a)
Q14.WAP to calculate in how many days a work will be completed by three
persons A, B and C together A, B, C take x, y and z respectively to do the same
joj alone. The formula to calculate the no. of days if they work together is
=(x*y*z)/((x*y)+(x*z)+(y*z)) days where x, y and z are given as input to the
program.
Program:
x=int(input("Enter The No of days A take"))
y=int(input("Enter The No of days B take"))
z=int(input("Enter The No of days C take"))
a=(x*y*z)/((x*y)+(x*z)+(y*z))
print(" No of Days Taken if they work together",d)
Q15. WAP to input a value in tones and convert it to into quintals and
kilograms.
Program:
x=int(input("Enter The Weight in Tonnes"))
a=x*10
b=x*1000
print("weight in Kilograms",b)
print("weight in Quintals",a)
Q16.WAP to input to numbers and swap them.
Program:
a=int(input("Enter a"))
b=int(input("Enter b"))
c=a
d=b
b=c
a=d
print("a=",a)
print("b=",b)
Q17.WAP to read details like name, class, and age of a student and then print
the details in the same line and then in separate lines .
Program:
x=input("Enter The Name of the student")
y=int(input("Enter The Class of the student"))
z=int(input("Enter The Age of the student"))
print(x,y,z)
print(x)
print(y)
print(z)
Q18.WAP to read a number and print n^2, n^3, and n^4.
Program:
n=float(input("Enter value of n"))
a=n**2
b=n**3
c=n**4
print("N^2",a)
print("N^3",b)
print("N^4",c)
Program List – 2
Q1.WAP to check whether a person is eligible for voting or not.(Voting
Age>=18).
Program:
a=int(input("Enter Your Age"))
if(a>18):
print("You are eligible for voting")
else:
print("You are not elgible")
Q2.Write a program to check whether a number is divisible by 7 or not.
Program:
a=int(input("Enter your age"))
if(a>=65):
print("You are a senior citizen")
else:
print("You are not a senior citizen")
Q3.WAP to check whether number accepted from the user is divisible by 2
and 3 both.
Program:
a=int(input("Enter the number"))
if(a%2==0 and a%3==0):
print("This number is divsible by 2 and 3")
else:
print("This number is not divsible by 2 and 3")
Q4.WAP to test the divisibility of a number with another number.
Program:
a=int(input("Enter First number"))
b=int(input("Enter Second number"))
if(a%b==0):
print(a,"isdivsibleby",b)
else:
print(a,"is not divsibleby",b)
Q5.WAP to accept temp in degree celcius and find whether water boils or
not.
Program:
a=int(input("Enter Temprature of water"))
if(a>=100):
print("The water is boiling")
else:
print("The water is not boiling")
Q6.WAP to check whether a number is divisible by 7 or not.
Program:
a=int(input("Enter The Number"))
if(a%7==0):
print("The Number is divisble by 7")
else:
print("The Number is not divisble by 7")
Q7.Any integer is input to find out whether it is an odd or even number.
Program:
a=int(input("Enter The Number"))
if(a%2==0 and a==0):
print("The Number is even")
else:
print("The Number is odd")
Q8.WAP to display hello if the number entered is a multiple of 5 otherwise
print bye.
Program:
a=int(input("Enter The Number"))
if(a%5==0):
print("Hello")
else:
print("Bye")
Q9.WAP to ask the user a length in centimeter if a –ve number the program
should tell the user that the entry is invalid .Otherwise the program should
convert the length to inches and print out the result .
Program:
a=int(input("Enter length in centimetres"))
if(a>=0):
b=a/2.54
print("Length in inches=",b)
else:
print("The Entry is invalid")
Q10.If the ages of Ram, Shyam and Ajay are input to determine the youngest
among them.
Program:
a=int(input("Enter The Age of Ram"))
b=int(input("Enter The Age of Shyam"))
c=int(input("Enter The Age of Ajay"))
if(a<b<c):
print("Ram is youngest")
if(b<c<a):
print("Shyam is youngest")
if(c<a<b):
print("Ajay is youngest")
if(a<c<b):
print("Ram is youngest")
if(b<a<c):
print("Shyam is youngest")
if(c<b<a):
print("Ajay is youngest")
Q11.WAP to find whether the number is +ve ,-ve or zero.
Program:
a=int(input("Enter The Number"))
if(a>0):
print("the Number is positive")
if(a==0):
print("The number is zero")
if(a<0):
print("The number is negative")
Q12.WAP to check whether a triangle is valid or no ,when three angles are
entered .
A triangle is valid if sum of the angles is equal to 180.
Program:
a=int(input("Enter Angle A"))
b=int(input("Enter Angle B"))
c=int(input("Enter Angle C"))
if(a+b+c==180):
print("The Triangle is Valid")
else:
print("The Triangle is Invalid")
Q13. Find the absolute value of a number entered through keyboard.
Program:
a=int(input("Enter The Number"))
if(a>=0):
print("The Value is absolute")
else:
b=a*-1
print("Absolute value is",b)
Q14. Given the length breath of a rectangle to find whether the are of the
rectangle is greater than its perimeter.
Program:
a=int(input("Enter The Length of Rectangle"))
b=int(input("Enter The Breath of Rectangle"))
c=a*b
d=2*(a+b)
if(a>d):
print("The Area is Greater than the Perimtre")
else:
print("The Area is Greater than the Perimtre")
Q15. If the cost price and selling price are entered, write a program to check
whether the seller has made a profit or a loss.
Program:
a=int(input("Enter the cost price"))
b=int(input("Enter the selling price"))
if(a>b):
print("The seller made a loss")
print("loss=",a-b)
else:
print("The seller made a profit")
print("profit=",b-a)
Q16.WAP to that reads two numbers and a arithmetic operator and display
the results.
(Example:input 3,5,+, so it will display 8)
Program:
a=int(input("Enter First Number"))
b=int(input("Enter Second Number"))
c=input("Enter Arithmetic Operator")
if(c=="+"):
d=a+b
print("The Answer is",d)
if(c=="-"):
e=a-b
print("The Answer is",e)
if(c=="*"):
f=a*b
print("The Answer is",f)
if(c=="/"):
g=a/b
print("The Answer is",g)
Q17.Write a program to accept percentage from the user and display the
grades according to the following criteria:
Marks Grade
>90 A
>80 and <=90 B
>=60 and <=80 C
Below 60 D
Program:
a=int(input("Enter Percentage"))
if(a>90):
print("Grade is A1")
if(90>a>80):
print("Grade is A2")
if(80>a>60):
print("Grade is B1")
if(a<60):
print("Grade is B2")
Q18.Write a program to accept a number from 1 to 7 and display the name of
the day like 1 Sunday, 2 Tuesday and so on.
Program:
a=int(input("Enter Number of the Day"))
if(a==1):
print("The day is Monday")
elif(a==2):
print("The day is Tuesday")
elif(a==3):
print("The day is Wednesday")
elif(a==4):
print("The day is Thursday")
elif(a==5):
print("The day is Friday")
elif(a==6):
print("The day is Saturday")
elif(a==7):
print("The day is Sunday")
else:
print("the number entered is invalid")
Q19.Accept any city from the user and display the monument as per the
following list:
City Monument
Delhi Red Fort
Agra Taj Mahal
Jaipur Jal Mahal
Program:
a=input("Enter the name of a city")
if(a=="Delhi"):
print("Red Fort")
elif(a=="Jaipur"):
print("Jal Mahal")
elif(a=="Agra"):
print("Taj Mahal")
else:
print("No data available")
Q20.WAP to check whether a character is vowel or not.
Program:
a=input("Enter The Alphabet")
if(a=="a"or a=="e"or a=="i"or a=="o"or a=="u"):
print("It is a vowel")
else:
print("It is a consonant")
Q21.Accept the following from the user and calculate the percentage of class
attended :
a. Total number of working days .
b. Total number of days for absent.
After calculating percentage show that, if the percentage is less than 75%,
than student will not be able to sit in exam.
Program:
a=int(input("Enter number of days present"))
b=int(input("Enter number of days absent"))
c=a+b
d=(a/c)*100
if(d<75):
print("The student cannot sit in the exam")
else:
print("The student can sit in the exam")
Q22.WAP to print whether a given character is an uppercase or lowercase
character or a digit or any other special character.
Program:
a=input("Enter the character numbe or special symbol")
if(a.isupper()):
print("This is a Uppercase character")
elif(a.islower()):
print("This is a Lowerrcase character")
elif(a.isdigit()):
print("This is a digit")
else:
print("this is a special character")
Q23.WAP to calculate roots and print the roots of the quadratic equation
ax^2+bx+c=0
Program:
a=int(input("Enter a"))
b=int(input("Enter b"))
c=int(input("Enter c"))
d=(b**2)-(4*a*c)
if(d>0):
p=(-b+(d**(1/2)))/2*a
q=(-b-(d**(1/2)))/2*a
print("Roots are",p,q)
elif(d==0):
p=-b/(2*a)
print("Root is",p)
else:
print("no roots")
Q24.WAP to check whether the last digit of a number is divisible by 3 or not.
Program:
a=float(input('enter the number'))
l=a%10
if(l%3==0):
print('last digit is divisible')
else:
print('indivisible')
Q25. WAP to check whether the rectangle made by entering side given by the
user is a square.
Program:
a=int(input('enter the length'))
b=int(input('enter the breadth'))
if(a==b):
print('it is a square')
else:
print('it is a rectangle')
Q26. WAP to decide if the employee in the company will get a bonus and its
amount or not based on his /her years of service . If years of service are more
than 5 years bonus would be 5 % else no bonus.
Program:
a=int(input("Enter The Year of Service"))
b=int(input("Enter The Salary"))
if(a>=5):
c=b+(b*0.05)
print("Your new salary is",c)
else:
("sorry not eligible")
Q27. WAP to compute gross salary. Taking names of employee and and basic
salary as an input.
GRADE BASIC DA HRA
GRADE I >45000 40% 30%
GRADE II >30000 AND <45000 40% 25%
GRADE III <30000 AND >15000 30% 20%
GRADE IV <15000 30% 15%
Program:
s=int(input("Enter Basic Salary"))
b=0.4*s
c=0.3*s
B=0.3*s
C=0.25*s
D=0.2*s
E=0.15*s
g=b+B+s
h=b+C+s
i=c+D+s
j=c+E+s
if(s>=45000):
print("Gross Salary=",g)
if(45000>s>=30000):
print("Gross Salary=",h)
if(30000>s>=15000):
print("Gross Salary=",i)
if(s<15000):
print("Gross Salary=",j)
Q28. WAP to calculate simple interest and use the rate 5% if the principal
interest amount is less than 25000 else the rate would be 8%.
Program:
a=int(input("Enter The Principal Amount"))
b=int(input("Enter The Time in Years"))
if(a<25000):
c=(a*b*5)/100
print("The SI is",c)
else:
c=(a*b*8)/100
print("The SI is",c)
Q29. WAP to calculate the BMI of the person and tell the status of weight as
follows
NUTRITIONAL STATUS BMI CUT OFF
Underweight less than 18.5
Normal 18.5 to 24.9
Overweight 25 to 29.9
Obese 30 or above
Program:
a=int(input("Enter the weight in Kg"))
b=int(input("Enter the height in meters"))
c=a/b**2
if(c<18.5):
print("Underweight")
if(18.5<c<24.9):
print("Normal")
if(25<c<29.9):
print("overweight")
if(c>30):
print("obese"))
Q30. WAP to calculate bonus for employee . If the person is male and salary is less
than 50000 , bonus would be 10% else 15%. And if the employee is female and
salary is less than 50000 , bonus would be 20% of the salary where salary is less
than 50000 otherwise bonus would be 25%.
Program:
a=int(input("Enter Old Salary"))
b=input("Enter Gender")
if(a<50000 and b=="Male"):
c=a+(0.05*a)
print("New Salary is",c)
elif(a<50000 and b=="Female"):
c=a+(a*0.2)
print("New Salary is",c)
elif(a>=50000 and b=="Male"):
c=a+(a*0.15)
print("New Salary is",c)
elif(a>=50000 and b=="Female"):
c=a+(a*0.25)
print("New Salary is",c)
Q31. WAP to check the type of triangle based on sides.
Program:
a=int(input("Enter First Side"))
b=int(input("Enter Second Side"))
c=int(input("Enter Third Side"))
if(a==c and b==c and a==b):
print("This is a Equi Triangle")
elif(a==b and b!=c):
print("This is a Isoceleas Triangle")
elif(b==c and c!=a):
print("This is a Isoceleas Triangle")
elif(a==c and c!=b):
print("This is a Isoceleas Triangle")
else:
print("This is a scalene Triangle")
Loop Questions
Q1.Print natural numbers till 10.
Program:
for i in range(1,11):
print(i)
Q2.Print even numbers till 10.
Program:
for i in range(0,11,2):
print(i)
Q3.Print odd numbers till 10.
Program:
for i in range(1,10,2):
print(i)
Q4.Print sum of even numbers till 100.
Program:
s=0
for i in range(0,101,2):
s=s+i
print(s)
Q5.Print sum of odd numbers till 100.
Program:
s=0
for i in range(1,101,2):
s=s+i
print(s)
Q6.Print Product of even numbers till 100.
Program:
s=1
for i in range(2,101,2):
s=s*i
print(s)
Q6.Print Product of odd numbers till 100.
Program:
s=1
for i in range(1,101,2):
s=s*i
print(s)
Q7.Print table of a number.
Program:
s=int(input("Enter a number"))
for i in range(1,11):
c=s*i
print(c)
Q8.Print sum of digits of a number.
Program:
a=int(input("Enter the number"))
s=0
while(a>0):
b=a%10
a=a//10
s=s+b
print(s)
Q9.Take a number and print the sum of its digits.
Program:
a=int(input("Enter the number"))
b=0
while(a>0):
d=a%10
b=b+d
a=a//10
print(b)
Q10.Input a number and print its reverse of digits.
Program:
a=int(input("Enter the number"))
b=0
while(a>0):
d=a%10
b=b*10+d
a=a//10
print(b)
Program List - 3
Q1.WAP to print all natural numbers from 1 to using while/for loop.
Program:
For:
n=int(input("Enter the limit"))
for i in range(1,n+1):
print(i)
While:
n=int(input("Enter the limit"))
a=0
while(a<n):
a=a+1
print(a)
Q2.WAP to print all natural numbers from n to 1 in reverse order using
while/for loop.
Program:
While:
a=int(input("Enter the starting point"))
while(a>1):
a=a-1
print(a)
For:
a=int(input("Enter the starting point"))
for i in range(a,0,-1):
print(i)
Q3.WAP to print all even numbers between 1to n using for/while loop.
Program:
For:
n=int(input("Enter the limit"))
for i in range(2,n+1,2):
print(i)
While:
a=int(input("Enter the limit"))
b=0
a=a-1
while(b<a):
b=b+2
print(b)
Q4.WAP to print all odd numbers between 1to n using for/while loop.
Program:
For:
n=int(input("Enter the limit"))
for i in range(1,n+1,2):
print(i)
While:
a=int(input("Enter the limit"))
b=-1
a=a-1
while(b<a):
b=b+2
print(b)
Q5.WAP to find the sum of all natural numbers form 1 to n.
Program:
While:
a=int(input("Enter the limit"))
b=0
c=0
while(b<a):
b=b+1
c=c+b
print(c)
For:
a=int(input("Enter the limit"))
b=0
c=0
for i in range(0,a+1):
c=c+i
print(c)
Q6.WAP to find sum of all even numbers from 1 to n.
Program:
For:
n=int(input("Enter the limit"))
c=0
for i in range(2,n+1,2):
c=c+i
print(c)
While:
a=int(input("Enter the limit"))
b=0
a=a-1
c=0
while(b<a):
b=b+2
c=b+c
print(c)
Q7.WAP to print sum of all odd numbers from n to 1.
Program:
For:
n=int(input("Enter the limit"))
c=0
for i in range(1,n+1,2):
c=c+i
print(c)
While:
a=int(input("Enter the limit"))
b=-1
a=a-1
c=0
while(b<a):
b=b+2
c=b+c
print(c)
Q8.WAP to print multiplication table of any number using for/while loop.
Program:
s=int(input("Enter a number"))
for i in range(1,11):
c=s*i
print(c).
Q9.WAP to count number of digits using while loop.
Program:
a=int(input("Enter the number"))
d=0
while(a>0):
a=a//10
d=d+1
print(d)
Q10.WAP to calculate the sum of digits of a number using while loop.
Program:
a=int(input("Enter the number"))
b=0
while(a>0):
d=a%10
b=b+d
a=a//10
print(b)
Q11.WAP to calculate the product the digits of a number using while loop.
Program:
a=int(input("Enter the number"))
b=1
while(a>0):
d=a%10
b=b*d
a=a//10
print(b)
Q12.Accept 10 numbers from the user and display there average.
Program:
b=0
for i in range(1,11):
a=int(input("Enter a number"))
b=a+b
c=b/10
print(c)
Q13.WAP to check whether a 3 digit number is Armstrong or not.-using while
loop.
Program:
a=int(input("Enter the number"))
g=a
e=a
c=0
b=0
while(a>0):
f=a%10
a=a//10
c=c+1
while(e>0):
d=e%10
b=(d**c)+b
e=e//10
if(g==b):
print("the number is an armstrong number")
else:
print("this is not an armstrong number")
Q14.WAP to find the factorial of any number using while/for loop.
Program:
a=int(input("Enter a number"))
b=1
for i in range(1,(a+1)):
b=b*i
print(b)
Q15.WAP to enter a number and
print its reverse.
Program:
a=int(input("Enter the number"))
b=0
while(a>0):
d=a%10
b=b*10+d
a=a//10
print(b)
Q16.WAP to check whether a number is palindrome or not.
Program:
a=int(input("Enter the number"))
c=a
b=0
while(a>0):
d=a%10
b=b*10+d
a=a//10
if(b==c):
print("the number is palindrome")
else:
print("the number is not palindrome")
Q17.WAP to print Fibonacci series up to n terms.
Program:
n=int(input("Enter the limit"))
a=0
b=1
print(0)
print(1)
for i in range(1,n+1):
c=a+b
print(c)
a=b
b=c
Q18.WAP to print the following patterns using for while loop.
A.
Program:
n=4
for i in range(1,n+1):
for i in range(1,i+1):
print('*',end='')
print()
B.
Program:
n=1
a=1
for i in range(1,5):
n=a
for j in range(1,i+1):
print(n,end='')
n=n+1
print()
C.
Program:
n=0
for i in range(1,5):
n=n+2
for j in range(1,i+1):
print(n,end='')
print()
D.
Program:
n=0
for i in range(1,5):
n=n+1
a=n
for j in range(1,i+1):
print(n,end='')
n=n-1
n=a
print()
E.
Program:
n=1
a=1
for i in range(1,5):
n=a
for j in range(1,i+1):
print(n,end='')
n=n+1
print()
Q19.WAP to print the following series: 1 4 7 10…..n using loops.
Program:
n=int(input("Enter the limit"))
for i in range(1,n+1,3):
print(i,end=' ')
Q20.WAP to check whether a given number is prime or not.
Program:
n=int(input("Enter the number"))
for j in range(2,n):
if(n%j==0):
f=1
break
else:
f=0
if(f==0):
print("This is a prime number")
else:
print("This is not a prime number")
Q21.WAP to print prime numbers from 2 to n.
Program:
n=int(input("Enter the limit"))
a=n
c=2
d=0
print(2)
for i in range(3,n+1):
for j in range(2,i):
if(i%j==0):
f=1
break
else:
f=0
if(f==0):
print(i)