Python Practical Worksheet
Python Practical Worksheet
Program 1
number =7
print(Square of 7 is:',square)
Program 2
m= km*1000
print('Distance in meter is:',m)
Program 3
area-length*breadth
perimeter-2*(lengthtbreadth)
Program 4
# Write a python program to calculate area of a triangle with base and height
area (base*height)/2
1
Program 5
total=cnglishtmaths+science
average = total/3
Arogram 6
# Write a python program to check if a person can vote
else:
Program 7
print("Youscored A+")
elif mark>65:
print("You scored C)
elif mark>45:
2
else:
print("Failed")
Mrogram8
# Write a python program to input a number and check if number is positive, negative or zero.
if num =0:
if num 0:
else:
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):
#while loop
sum =0
num =l
while num < 11:
3
Programn 10
,
#Write a python program to add first n natural numbers using for loop and while loop
#for loop
sum 0
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.
#for loop
sum odd =0
Sum even =0
if (i%2) =0:
sum even =sum eventi
else:
4
print("sum of first n odd numbers =",sum odd)
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
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
students.remove("Vikram")
print(students)
5
students.append("Jay")
print(students)
del students[1]
print(students)
Program 15
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