0% found this document useful (0 votes)
154 views

CS Practical File For Class 11

The document contains 22 programming problems and their solutions in Python. The problems cover a range of concepts including accepting user input, performing calculations, conditional logic, loops, patterns, and string manipulation. The solutions demonstrate basic Python syntax for variables, data types, arithmetic operators, conditional statements, for loops, functions, and printing output.

Uploaded by

harshkaur.636
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
154 views

CS Practical File For Class 11

The document contains 22 programming problems and their solutions in Python. The problems cover a range of concepts including accepting user input, performing calculations, conditional logic, loops, patterns, and string manipulation. The solutions demonstrate basic Python syntax for variables, data types, arithmetic operators, conditional statements, for loops, functions, and printing output.

Uploaded by

harshkaur.636
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

1.

Write a program to accepts two integers and print their


sum.

a=int(input('Enter the first integer:'))


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:-
COMPUTER SCIENCE

2.Write a program that accepts radius of a circle and


prints its area.

r=int(input('Enter the radius of circle:'))


Area=3.14*r**2
print('The area of the circle is:', Area)

OUTPUT:-

1
COMPUTER SCIENCE

3. 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')


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:-

2
COMPUTER SCIENCE

4. 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:-

3
COMPUTER SCIENCE

5. 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:-

4
COMPUTER SCIENCE

6. Write a program to find largest among three integers.

a=int(input('Enter the first integer:'))


b=int(input('Enter the second integer:'))
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:-

5
COMPUTER SCIENCE

7.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)

OUTPUT:-

6
COMPUTER SCIENCE

8.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)
OUTPUT:-

7
COMPUTER SCIENCE

9.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')

OUTPUT:-

8
COMPUTER SCIENCE

10.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')

OUTPUT:-

9
COMPUTER SCIENCE

11.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)
ifx%2!=0:
print('The value of square is:',a)
else:
print('The value of square root is:',b)

OUTPUT:-

10
COMPUTER SCIENCE

12.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:
print('The number is a negative number')

OUTPUT:-

11
COMPUTER SCIENCE

13.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

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')

12
COMPUTER SCIENCE

OUTPUT:-

13
COMPUTER SCIENCE

14.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:-

14
COMPUTER SCIENCE

15.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:-

15
COMPUTER SCIENCE

16.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:-

16
COMPUTER SCIENCE

17. Write a program to create a triangle of stars using


nested loop.
for i inrange(1,6):
print()
for j inrange(1,i):
print('*',end=' ')

OUTPUT:-

17
COMPUTER SCIENCE

18.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=' ')
print()
OUTPUT:-

18
COMPUTER SCIENCE

19.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 inrange(4,i,-1):
print(j,end=' ')
else:
print()

OUTPUT:-

19
COMPUTER SCIENCE

20.Program that reads a line and print its statistics like:


Number of uppercase letters:
Number of lowercase letters:
Number of alphabets:
Number of digits:

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)

20
COMPUTER SCIENCE

OUTPUT:-

21
COMPUTER SCIENCE

21.Write a program that reads a string and then prints a


string that capitalizes every other letter in the string.
string=input('Enter a string:')
str2=''
x=str1.split()
for a in x:
str2+= a.capitalize()+' '
print('Alternatively capitalized string:',string2)
OUTPUT:-

22

You might also like