COMPUTER SCIENCE
PROGRAM FILE - 2024-25
CLASS : XI-A
COMPUTER SCIENCE
INDEX
NO. AIM PAGE NO. SIGN
1) Write a program to accepts two integers and
print their sum.
2) Write a program that accepts radius of a
circle and prints its area.
3) Write a program that accepts base and
height and calculate the area of triangle.
4) Write a program that inputs a student’s
marks in three subjects (out of 100) and
prints the percentage marks.
5) Write a program to compute area of square
andtriangle.
6) Write a program to calculate simple interest.
7) Write a program to read two numbers and
prints their quotient and reminder.
8) Write a program to find whether a given
number is even or odd.
9) Write a program to find largest among three
integers.
10) Write a program to find lowest among three
integers.
1
COMPUTER SCIENCE
11) Write a program that accepts length and
breadth of rectangle and calculate its area.
12) Write a program that accepts weight in Kg
and height in meters and calculate the BMI.
13) Write a program that reads the number n
and print the value of n², n³ and n⁴.
14) Write a program to accept the marks of five
subjects and calculate the average marks.
15) Write a program to accept theheight in cm
and convert it into feet and inches.
16) Write a program that accepts the age and
print if one is eligible to vote or not.
17) Write a program that accepts two numbers
and check if the first number is fully divisible
by second number or not.
18) Write a program to read base,width and
height of parallelogram and calculate its area
and perimeter.
19) Write a program to accept the year and
check if it is a leap year or not.
20) Write a program to input a number and print
its square if it is odd, otherwise print its
square root.
21) Write a program to input a number and
check whether it is positive, negative or zero.
22) Write a program to input percentage marks
of a student and find the grade as per
following criterion:
2
COMPUTER SCIENCE
Marks Grade
>=90 A
75-90 B
60-75 C
Below 60 D
23) Write a program to enter a number and
check if it is a prime number or not.
24) Write a program to display a menu for
calculating area of circle or perimeter of the
circle.
25) Write a program that reads two numbers and
an arithmetic operator and displays the
computed result.
26) Write a program to print whether a given
character is an uppercase or a lowercase
character or a digit or any other character.
27) Write a program to print sum of natural
numbers between 1 to 7. Print the sum
progressively i.e. after adding each natural
number, print sum so far.
28) Write a program to calculate the factorial of
a number.
29) Write a program to create a triangle of stars
using nested loop.
30) Write a Python script to print Fibonacci
series’ first 20 elements.
31) Write a program to read an integer>1000 and
reverse the number.
32) Input three angles and determine if they
form a triangle or not.
33) Write python script to print following pattern.
1
1 3
1 3 5
1 3 5 7
3
COMPUTER SCIENCE
34) Write a program to print the following using a single
loop (no nested loops)
1
1 1
1 1 1
1 1 1 1
1 1 1 1 1
35) Write a program to print a pattern like:
4321
432
43
4
36) 44.Program that reads a line and print its
statistics like:
Number of uppercase letters:
Number of lowercase letters:
Number of alphabets:
Number of digits:
37) Write a program that reads a string and
checks whether it is a palindrome string or
not.
1.Write a program to accepts two integers and print their
sum.
a=int(input('Enter the first integer:'))
4
COMPUTER SCIENCE
b=int(input('Enter the second integer:'))
Sum=a+b
print('The two integers are:', a, b)
print('The sum of two integers are:', Sum)
OUTPUT:-
2.Write a program that accepts radius of a circle and
prints its area.
r=int(input('Enter the radius of circle:'))
5
COMPUTER SCIENCE
Area=3.14*r**2
print('The area of the circle is:', Area)
OUTPUT:-
3. Write a program that accepts base and height and
calculate the area of triangle.
b=float(input('Enter the base of triangle:'))
h=float(input('Enter the height of triangle:'))
Area=(1/2)*b*h
print('The area of triangle is:', Area)
OUTPUT:-
4. Write a program that inputs a student’s marks in three
subjects (out of 100) and prints the percentage marks.
print('Enter the marks of three subject out of 100')
6
COMPUTER SCIENCE
a=float(input('Enter the marks of first subject:'))
b=float(input('Enter the marks of second subject:'))
c=float(input('Enter the marks of third subject:'))
P=(a+b+c)/3
print('The percentage marks are:', P,'%')
OUTPUT:-
5. Write a program to compute area of square and
triangle.
a=float(input('Enter the value of side:'))
A=a**2
T=((3**0.5)/4)*a**2
print('The area of square is:', A)
print('The area of triangle is:', T)
OUTPUT:-
7
COMPUTER SCIENCE
6. Write a program to calculate simple interest.
P=float(input('Enter the principal amount in ₹:'))
R=float(input('Enter the rate of interest:'))
T=float(input('Enter the time in years:'))
SI=(P*R*T)/100
print('The simple interest is:', SI,'₹')
OUTPUT:-
7. Write a program to read two numbers and prints their
quotient and reminder.
a=float(input('Enter the dividend:'))
b=float(input('Enter the divisor:'))
Q=a//b
R=a%b
print('The quotient is:', Q)
8
COMPUTER SCIENCE
print('The remainder is:', R)
OUTPUT:-
8. Write a program to find whether a given number is even
or odd.
a=int(input('Enter the number:'))
if a%2==0:
print('The number is even')
else:
print('The number is odd')
OUTPUT:-
9. Write a program to find largest among three integers.
a=int(input('Enter the first integer:'))
b=int(input('Enter the second integer:'))
9
COMPUTER SCIENCE
c=int(input('Enter the third integer:'))
if a>b and a>c:
print(a, 'is the largest integer')
if b>a and b>c:
print(b, 'is the largest integer')
if c>a and c>b:
print(c, 'is the largest integer')
OUTPUT:-
10.Write a program to find lowest among three integer.
a=int(input('Enter the first integer:'))
b=int(input('Enter the second integer:'))
c=int(input('Enter the third integer:'))
ifa<b and a<c:
print(a, 'is the smallest integer')
ifb<a and b<c:
print(b, 'is the smallest integer')
10
COMPUTER SCIENCE
ifc<a and c<b:
print(c, 'is the smallest integer')
OUTPUT:-
11. Write a program to that accepts length and breadth of
rectangle and calculate its area.
l=float(input('Enter the length of rectangle:'))
b=float(input('Enter the breadth of rectangle:'))
area=l*b
print('Rectangle Specifications')
print('Length=',l)
print('Breadth=', b)
print('Area=', area)
11
COMPUTER SCIENCE
OUTPUT:-
12.Write a program that accepts weight in Kg and height in
meters and calculate the BMI.
W = float(input('Enter the weight in Kg:'))
H = float(input('Enter height in meters:'))
BMI=W/(H**2)
print('BMI is:', BMI)
OUTPUT:-
12
COMPUTER SCIENCE
13.Write a program that reads the number n and print the
value of n², n³ and n⁴.
a=float(input('Enter the value of n:'))
b=a**2
c=a**3
d=a**4
print('The value of n² is:', b)
print('The value of n³ is:', c)
print('The value of n⁴ is:', d)
13
COMPUTER SCIENCE
OUTPUT:-
14.Write a program to accept the marks of five subjects and
calculate the average marks.
a=float(input('Enter the marks of first subject:'))
b=float(input('Enter the marks of second subject:'))
c=float(input('Enter the marks of third subject:'))
d=float(input('Enter the marks of fourth subject:'))
e=float(input('Enter the marks of fifth subject:'))
Average=(a+b+c+d+e)/5
print('The average marks are:', Average)
14
COMPUTER SCIENCE
OUTPUT:-
15.Write a program to accept the height in cm and convert
it into feet and inches.
a=float(input('Enter your height in centimeters:'))
Feet=a*0.032
Inch=a*0.393
print('Your height in feet is:', Feet)
15
COMPUTER SCIENCE
print('Your height in inch is:', Inch)
OUTPUT:-
16.Write a program that accepts the age and print if one is
eligible to vote or not.
a=int(input('Enter your age:'))
if a>=18:
print('You are eligible to vote')
else:
print('You are not eligible to vote')
16
COMPUTER SCIENCE
OUTPUT:-
17.Write a program that accepts two numbers and check if
the first number is fully divisible by second number or not.
a=float(input('Enter the first number:'))
b=float(input('Enter the second number:'))
if a%b==0:
print('The first number is fully divisible by second
number')
else:
print('The first number is not fully divisible by
second number')
17
COMPUTER SCIENCE
OUTPUT:-
18.Write a program to read base, width and height of
parallelogram and calculate its area and perimeter.
b=float(input('Enter the base of parallelogram:'))
w=float(input('Enter the width of parallelogram:'))
h=float(input('Enter the height of parallelogram:'))
Area=b*h
Perimeter=2*(b+w)
print('The area of parallelogram is:', Area)
18
COMPUTER SCIENCE
print('The perimeter of parallelogram is:', Perimeter)
OUTPUT:-
19.Write a program to accept the year and check if it is a
leap year or not.
a=int(input('Enter the year:'))
if a%4==0:
print('This year is a leap year')
else:
print('This year is not a leap year')
19
COMPUTER SCIENCE
OUTPUT:-
20.Write a program to input a number and print its square
if it is odd, otherwise print its square root.
x=float(input(‘Enter the number:’))
import math
a=math.pow(x,2)
b=math.sqrt(x)
if x%2!=0:
print('The value of square is:',a)
else:
20
COMPUTER SCIENCE
print('The value of square root is:',b)
OUTPUT:-
21.Write a program to input a number and check whether it
is positive, negative or zero.
a=float(input('Enter the number:'))
if a>=0:
if a==0:
print('The number is zero')
else:
print('The number is a positive number')
else:
21
COMPUTER SCIENCE
print('The number is a negative number')
OUTPUT:-
22.Write a program to input percentage marks of a student
and find the grade as per following criterion:
Marks Grade
>=90 A
75-90 B
60-75 C
Below 60 D
22
COMPUTER SCIENCE
a=float(input('Enter the percentage marks:'))
if a>=90:
print('The student has got an A grade')
elif a>=75 and a<90:
print('The student has got a B grade')
elif a>=60 and a<75:
print('The student has got a C grade')
else:
print('The student has got a D grade')
23
COMPUTER SCIENCE
OUTPUT:-
24
COMPUTER SCIENCE
23. Write a program to enter a number and check if it is a
prime number or not.
num=int(input('Enter the number:'))
for i in range(2,num//2+1):
if num%i==0:
print('It is not a prime no.')
break
else:
print('It is a prime number')
OUTPUT:-
25
COMPUTER SCIENCE
24. Write a program to display a menu for calculating area
of circle or perimeter of the circle.
r=float(input(‘Enter the radius of the circle:’)
print(‘1.Calculate perimeter’)
print(‘2.Calculate area’)
choice=int(input(‘Enter your choice (1 or 2):’))
if choice==1:
peri=2*3.14159*r
print(‘Perimeter of the circle with radius’,r,’:’,peri)
else:
area=3.14159*r*r
print(‘Area of the circle of the radius’,r,’:’,area)
OUTPUT:-
26
COMPUTER SCIENCE
25.Write a program that reads two numbers and an
arithmetic operator and displays the computed result.
a=float(input('Enter the first number:'))
b=float(input('Enter the second number:'))
c=input('Enter the operator[/,*,+,-]:')
if c=='/':
r=a/b
elif c=='*':
r=a*b
elif c=='+':
r=a+b
elif c=='-':
r=a-b
else:
print('Invalid operator')
print(a,c,b,'=',r)
OUTPUT:-
27
COMPUTER SCIENCE
26.Write a program to print whether a given character is an
uppercase or a lowercase character or a digit or any other
character.
ch=input('Enter a single character:')
if ch>='A' and ch<='Z':
print('You have entered an uppercase character.')
elif ch>='a' and ch<='z':
print('You have entered an lowercase character.')
elif ch>='0' and ch<='9':
print('You have entered a digit.')
else:
print('You have entered a special character.')
OUTPUT:-
28
COMPUTER SCIENCE
27. Write a program to print sum of natural numbers
between 1 to 7. Print the sum progressively i.e. after adding
each natural number, print sum so far.
Sum=0
for n in range(1,8):
Sum+=n
print('Sum of natural numbers <=',n,'is',Sum)
OUTPUT:-
28.Write a program to calculate the factorial of a number.
29
COMPUTER SCIENCE
num=int(input('Enter a number:'))
fact=1
a=1
while a<=num:
fact*=a
a+=1
print('The factorial of',num,'is',fact)
OUTPUT:-
29. Write a program to create a triangle of stars using
nested loop.
for i in range(1,6):
30
COMPUTER SCIENCE
print()
for j in range(1,i):
print('*',end=' ')
OUTPUT:-
30.Write a Python script to print Fibonacci series’ first 20
elements.
first=0
second=1
print(first, end=' ')
print(second,end=' ')
for a in range(1,19):
third=first+second
print(third,end=' ')
first,second=second,third
31
COMPUTER SCIENCE
OUTPUT:-
31.Write a program to read an integer>1000 and reverse
the number.
num=int(input('Enter a number (>1000):'))
tnum=num
reverse=0
while tnum>0:
digit=tnum%10
reverse=reverse*10+digit
tnum=tnum//10
print('Reverse of',num,'is',reverse)
OUTPUT:-
32
COMPUTER SCIENCE
32.Input three angles and determine if they form a triangle
or not.
angle1=angle2=angle3=0
angle1=float(input('Enter the first angle:'))
angle2=float(input('Enter the second angle:'))
angle3=float(input('Enter the third angle:'))
if angle1+angle2+angle3==180:
print('The angles form a triangle')
else:
print('The angles do not form a triangle')
33
COMPUTER SCIENCE
OUTPUT:-
33.Write python script to print following pattern.
1
1 3
1 3 5
1 3 5 7
for a in range(3,10,2):
print()
for b in range(1,a,2):
print(b, end=' ')
34
COMPUTER SCIENCE
print()
OUTPUT:-
34.Write a program to print the following using a single
loop (no nested loops)
1
1 1
1 1 1
1 1 1 1
1 1 1 1 1
n=1
35
COMPUTER SCIENCE
for a in range(5):
print(n)
print()
n=n*10+1
OUTPUT :-
35.Write a program to print a pattern like:
4 3 2 1
4 3 2
4 3
4
for i in range(4):
for j in range(4,i,-1):
36
COMPUTER SCIENCE
print(j,end=' ')
else:
print()
OUTPUT:-
36.Program that reads a line and print its statistics like:
Number of uppercase letters:
Number of lowercase letters:
Number of alphabets:
Number of digits:
37
COMPUTER SCIENCE
line=input('Enter a line:')
lowercount=uppercount=0
digitcount=alphacount=0
for a in line:
if a.islower():
lowercount+=1
elif a.isupper():
uppercount+=1
elif a.isdigit():
digitcount+=1
if a.isalpha():
alphacount+=1
print('Number of uppercase letters are:',uppercount)
print('Number of lowercase letters are:',lowercount)
print('Number of alphabets are:',alphacount)
print('Number of digits are:',digitcount)
OUTPUT:-
38
COMPUTER SCIENCE
37.Write a program that reads a string and checks whether
it is a palindrome string or not.
string=input('Enter a string:')
length=len(string)
mid=length//2
rev=-1
for a in range(mid):
if string[a]==string[rev]:
print(string,'is a palindrome.')
break
else:
39
COMPUTER SCIENCE
print(string,'is not a palindrome.')
break
OUTPUT:-
40