Practical Python Programs
Practical Python Programs
MAHENDRA HILLS
__________________________________________________________________________
Sub: Introduction to Python Class: IX
Practical Programs
Instructions:
1. Write all the programs in A4 size sheet neatly.
2. Staple all the papers in a booklet form.
3. Submit the booklet on Practical Exam day
___________________________________________________________________________
2.Write a program to find the whether a number is prime or not using 'while' loop.
num=int(input("enter a number"))
i=2
n=0
while i<num:
if num%i==0:
n=1
i=i+1
if n==0:
print(num, "is a prime number")
elif n==1:
print(num, "is not a prime number")
List=[11,12,13,14,15]
sum=0
for i in List:
sum=sum+i
print(sum)
9.Create a list in Python of Students with following names- John, Alex, Andrew, Sam,
Nirav and Perform the following tasks on the list in sequence-
1) Print the whole list
2) Delete the name “Andrew” from the list
3) Add the name “Mahi” at the end
4) Remove the item which is at the second position.
10. a) Create a list num=[23,12,5,9,65,44], print the elements from second to fourth
position using positive indexing, print the elements from position third to fifth using
negative indexing and print the reverse list.
b) Create a list of the first 10 even numbers, add 1 to each list item, and print the final
list.
even_numbers = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
even_numbers = [x + 1 for x in even_numbers]
print("List of first 10 even numbers after adding 1:", even_numbers)
c) Create a list List_1=[10,20,30,40], extend it with [14,15,12], sort, and print the final
list
List_1 = [10, 20, 30, 40]
List_1.extend([14, 15, 12])
List_1.sort()
print("Sorted List after extending:", List_1)