[go: up one dir, main page]

0% found this document useful (0 votes)
3 views39 pages

Practile CS

The document contains a series of programming exercises, each with a problem statement, code, and output. The exercises cover various topics such as arithmetic operations, area calculations, conditional statements, and data structures in Python. Each exercise is numbered and provides a clear example of how to implement specific programming concepts.

Uploaded by

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

Practile CS

The document contains a series of programming exercises, each with a problem statement, code, and output. The exercises cover various topics such as arithmetic operations, area calculations, conditional statements, and data structures in Python. Each exercise is numbered and provides a clear example of how to implement specific programming concepts.

Uploaded by

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

PRACTILE NO.

:- 02

Problem Statement :- Write a program to accepts two integers and print


their sum.

Code :-
a=int(input('Enter the first integer:'))
b=int(input('Enter the second integer:'))

Sum=a+b

print('The sum of two integers are:', Sum)

Output :-
PRACTILE NO. :- 03

Problem Statement :- Write a program that accepts radius of a circle and


prints its area.

Code :-
r= int(input('Enter the radius of circle:'))
Area= 3.14*r*r
print('The area of the circle is:', Area)

Output :-
PRACTILE NO. :- 05

Problem Statement :- Write a program that accepts base and height and
calculate the area of triangle.

Code :-
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 :-
PRACTILE NO. :- 11

Problem Statement :- Write a program to find whether a given number is


even or odd.

Code :-
a=int(input('Enter the number:'))
if a%2==0:
print('The number is even')
else:
print('The number is odd')

Output :-
PRACTILE NO. :- 08

Problem Statement :- Write a program to find largest among three integers.

Code :-
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 :-
PRACTILE NO. :- 23

Problem Statement :- Write a program that accepts weight in Kg and height


in meters and calculate the BMI.

Code :-
W = float(input('Enter the weight in Kg:'))
H = float(input('Enter height in meters:'))
BMI=W/(H**2)

print('BMI is:', BMI)

Output :-
PRACTILE NO. :- 19

Problem Statement :- Write a program to accept the marks of five subjects


and calculate the average marks.

Code :-
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 :-
PRACTILE NO. :- 14

Problem Statement :- Write a program that reads the number n and prints
the value of n², n³ and n⁴.

Code :-
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 :-
PRACTILE NO. :- 17

Problem Statement :- Write a program to accept the year and check if it is a


leap year or not.

Code :-
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 :-
PRACTILE NO. :- 12

Problem Statement :- Write a program to enter a number and check if it is a


prime number or not.

Code :-
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 :-
PRACTILE NO. :- 15

Problem Statement :- Write a program to calculate the factorial of a number.

Code :-
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 :-
PRACTILE NO. :- 24

Problem Statement :- Write python script to print following pattern.


1
13
135
1357

Code :-
for a in range(3,10,2):
print()
for b in range(1,a,2):
print(b, end=' ')
print()

Output :-
PRACTILE NO. :- 34

Problem Statement :- Program that reads a line and print its statistics like - Number
of uppercase letters, Number of lowercase letters, Number of alphabets and Number of
digits.

Code :-
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 :-
PRACTILE NO. :- 25

Problem Statement :- Write a program to print a pattern like:


4321
432
43
4

Code :-
for i in range(4):
for j in range(4,i,-1):
print(j,end=' ')
else:
print()

Output :-
PRACTILE NO. :- 27

Problem Statement :- WRITE A PROGRAM to accept values from user and


create a tuple.

Code :-
t=tuple()
n=int(input("How many values you want to enter: "))
for i in range(n):
a=input("Enter Number: ")
t=t+(a,)
print("Entered Numbers are: ")
print(t)

Output :-
PRACTILE NO. :- 28

Problem Statement :- Write a Python program to remove an item from a


tuple.

Code :-
tuplex = "l","e","a","r","n","p","y","t","h","o","n","4","c","b","s","e"
print("Tuple Before Removing an item")
print(tuplex)

listx = list(tuplex)
listx.remove("4")

tuplex = tuple(listx)
print("Tuple After Removing an item '4'")
print(tuplex)

Output :-
PRACTILE NO. :- 01

Problem Statement :-. Print Welcome message.

Code :-
print(“Welcome”)

Output :-
PRACTILE NO. :- 04

Problem Statement :-Write a program to compute area of square.

Code :-
a=float(input('Enter the value of side:'))

A=a**2

print('The area of square is:', A)

Output :-
PRACTILE NO. :- 09

Problem Statement :- Write a program to find lowest among three integers.

Code :-
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')
ifc<a and c<b:
print(c, 'is the smallest integer')

Output :-
PRACTILE NO. :- 18

Problem Statement :- Write a program that inputs a student’s marks in three


subjects (out of 100) and prints the percentage marks.

Code :-
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 :-
PRACTILE NO. :- 21

Problem Statement :- Write a program to accept the height in cm and


convert it into feet and inches.

Code :-
a=float(input('Enter your height in centimeters:'))

Feet=a*0.032
Inch=a*0.393

print('Your height in feet is:', Feet)


print('Your height in inch is:', Inch)

Output :-
PRACTILE NO. :- 22

Problem Statement :- Write a program that accepts the age and print if one
is eligible to vote or not.

Code :-
a=int(input('Enter your age:'))
if a>=18:
print('You are eligible to vote')
else:
print('You are not eligible to vote')

Output :-
PRACTILE NO. :- 13

Problem Statement :- Write a program that accepts two numbers and check
if the first number is fully divisible by second number or not.

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

Output :-
PRACTILE NO. :- 10

Problem Statement :- Write a program to input a number and check whether


it is positive, negative or zero.

Code :-
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 :-
PRACTILE NO. :- 20

Problem Statement :- Write a program to input percentage marks of a


student and find the grade.

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

Output :-
PRACTILE NO. :- 16

Problem Statement :- Write a program to calculate and print the roots of a


quadratic equation ax²+bx+c=0.

Code :-
import math
print('For quadratic equation, ax²+bx+c=0,enter coefficents below')
a=int(input('Enter a:'))
b=int(input('Enter b:'))
c=int(input('Enter c:'))
if a==0:
print('Value of a should not be zero')

else:
d=b*b-4*a*c
if d>0:
root1=(-b+math.sqrt(d))/(2*a)
root2=(-b-math.sqrt(d))/(2*a)
print('Roots are real and unequal')
print('Root1=',root1,',Root2=',root2)
elif d==0:
root1=-b/2*a
print('Roots are real and equal')
print('Root1=',root1,',Root2=',root1)
else:
print('Roots are complex and imaginary')
Output :-
PRACTILE NO. :- 29

Problem Statement :- Show some list operations on the following lists.

Code :-
L1 = ['Red','Green','Blue']
L2 = ['Cyan', 'Magenta', 'Yellow','Black']

print(L1+L2)
print(L1*3)
print(len(L2))
print(L1[0:2])

Output :-
PRACTILE NO. :- 26

Problem Statement :- Write a program to create a design of stars using


nested loop.

Code :-
for i in range(1,6):
print()
for j in range(1,i):
print('*',end=' ')

Output :-
PRACTILE NO. :- 06

Problem Statement :- Input three angles and determine if they form a


triangle or not.

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

Output :-
PRACTILE NO. :- 07

Problem Statement :- Write a program to read base, width and height of


parallelogram and calculate its area and perimeter.

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


print('The perimeter of parallelogram is:', Perimeter)

Output :-
PRACTILE NO. :- 33

Problem Statement :- Access each item of the dictionary or traverse a


dictionary using for loop.

Code :-
dict2= {'Raman': 76, 'Suman': 56, 'Sahil': 34, 'Amit': 85}
print(dict2)

for key in dict2:


print(key,':',dict2[key])

Output :-
PRACTILE NO. :- 31

Problem Statement :- Enter a string and make ever letter capital of that
string.

Code :-
a = input("Enter a string:")

b = a.upper()
print(b)

Output :-
PRACTILE NO. :- 30

Problem Statement :-Modify the given Dictionary as per the need.

Code :-
dict1= {'Raman': 76, 'Suman': 56, 'Sahil': 34, 'Amit': 85}

dict1['John'] = 77
dict1['Sahil'] = 50

del dict1['Suman']

print(dict1)

Output :-
PRACTILE NO. :- 35

Problem Statement :- Find mean, median and mode of following data.

Code :-
import statistics
a = [2,5,3,3,10,3,67,5,2,1]

x= statistics.mean(a)
y= statistics.median(a)
z= statistics.mode(a)

print("Mean of the following data is:",x)


print("Median of the following data is:",y)
print("Mode of the following data is:",z)

Output :-
PRACTILE NO. :- 32

Problem Statement :- Perform slicing on the following truple.

Code :-
tuple1 =(('Physics',89),('Chemistry',93),('Maths',96), ('Comp.Sc.',83))

print(tuple1[3])
print(tuple1[0:2])
print(tuple1[-3])
print(tuple1[0:4:2])

Output :-
Computer Science
Practical File…

By,
DHRUV DEV KHEDKAR
Class 11th A
Roll No. 19
THANK
YOU…

You might also like