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

Python Practical Worksheet

Uploaded by

ysultana455
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Python Practical Worksheet

Uploaded by

ysultana455
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

PYTHON PRACTICAL PROGRAMS

Program 1

#Write a python program to find the square of 7

number =7

Square = number **2

print(Square of 7 is:',square)

Program 2

# Write a python program to convert length in kilometer to meter

km = float(input('Enter the distance in kilometer: ))

m= km*1000
print('Distance in meter is:',m)

Program 3

# Write a python program to calculate Area and Perimeter of a rectangle

length = float(input("Enter the length of the rectangle: ")


breadth = float(input("Enter the brcadth of the rectangle: "))

area-length*breadth

perimeter-2*(lengthtbreadth)

print("Area of the rectangle is ", area)

print("Perimeterof the rectangle is:", perimeter)

Program 4

# Write a python program to calculate area of a triangle with base and height

base = float(input("Enter the base of the triangle:"))

height float(input("Enter the height of the triangle: ")

area (base*height)/2

print("Area of triangle is: ", area)

1
Program 5

# Write a python program to calculate the average marks of 3 subjects

english = float(input("Enter your marks in cnglish: "))

maths = your marks


float(input("Enter in maths: ")

science = your marks


float(input("Enter in science: "))

total=cnglishtmaths+science
average = total/3

print("Averagemark of 3 subjects are: ", average)

Arogram 6
# Write a python program to check if a person can vote

age =int(input(Enter your age:')

if age >= 18:

print(Youare eligible to vote')

else:

print(You are not eligible to vote')

Program 7

# Write a python program to check the grade of a student

mark = float(input("Enter your mark")

if mark > 85:

print("Youscored A+")

elif mark > 75:

print("You scored A")

elif mark>65:

print("You scored B")

elif mark> 55:

print("You scored C)
elif mark>45:

print("You scored D")

2
else:

print("Failed")

Mrogram8
# Write a python program to input a number and check if number is positive, negative or zero.

num = float(input("Enter a number: ")

if num =0:

if num 0:

print("The number you entered is Zero")

else:

print("The number you entered is a positive number")


else:

print("The number you entered is a negative number")

tProgram 9
# Write a python program to add first 10natural numbers using for loop and while loop

#for loop

sum =0
for num in range(1,11):

Sum F Sum + numn

print("The sum of first 10 natural number is: ",sum)

#while loop

sum =0
num =l
while num < 11:

Sum Sum t numn


num num t1

print("The sum of first 10 natural number is: "sum)

3
Programn 10

,
#Write a python program to add first n natural numbers using for loop and while loop

n= int(input("Enter the limit:"))

#for loop

sum 0

for iin range(1,n+ 1):

Sum =Sum +i
print(sum)

#while loop

sum =)
i=1
while i<n+1:

sum =Sum +i
i= i+1

print(sum)

Program 11

AWrite a python program to add first n odd numbers and even numbers separately using for loop and
while loop.

n= int(input("Enter the limit:"))

#for loop

sum odd =0
Sum even =0

for iin range(1,n+1):

if (i%2) =0:
sum even =sum eventi

else:

sum odd =sumn odd+i

4
print("sum of first n odd numbers =",sum odd)

print("'sum of first n even numbers =",sum even)

Programn 12

# Write a python program to find the sum of all numbers stored in a list a =[6,5,3, 8, 4, 2, 5, 4, 11]

a= [6,5,3,8,4,2,5,4, 11]

sum 0 =
for x in a:

Sum =Sum+x
print("The sum of all the numbers stored in the list is:",sum)

Program 13

AWrite a python program to create a list num - (23,24,25,26,27,28,29]

Print the element in the list

Print the element from second to fourth position using positive indexing.
Print the element from third to fifth
position using negative indexing.

num - [23,24,25,26,27,28,291
for x in num:
print(x)

print(num[1:4])

print(num[-5:-2])

V Program 14

#Write a python program to create a list of


children selected for science quiz with the following name:
- Arjun, Sonakshi, Vikram,
Sandhya, Sonal, Isha and Kartik. Performn the
following task on the list in
sequence.

Print the whole list

Delete thename Vikram from the list


Add the name Jay at the end.
Remove the item which is at the second position.

students = "Arjun","Sonakshi","Vikram""Sandhya" "Sonal","Isha",


"Kartik"]
print(students)

students.remove("Vikram")
print(students)

5
students.append("Jay")
print(students)

del students[1]

print(students)

Program 15

#Write a python program to create a list list_1 =


[10,20,30,40J.

Add the elements [14,15,12]using the extend function.

Now sort the final list in ascending order and print it.

list l =[10,20,30,40]
list l.extend([14,15,12])

print(list_1)

list 1.sort)

print(list_1)

b, 3,10

You might also like