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

Practical Python Programs

The document provides practical programming exercises for Class IX students at Delhi Public School, Mahendra Hills, focusing on Python. It includes tasks such as calculating sums, checking for prime numbers, and manipulating lists. Students are instructed to neatly write and submit their programs on the practical exam day.

Uploaded by

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

Practical Python Programs

The document provides practical programming exercises for Class IX students at Delhi Public School, Mahendra Hills, focusing on Python. It includes tasks such as calculating sums, checking for prime numbers, and manipulating lists. Students are instructed to neatly write and submit their programs on the practical exam day.

Uploaded by

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

DELHI PUBLIC SCHOOL

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
___________________________________________________________________________

1.Program to add natural numbers upto sum = 1+2+3+...+n.


n = int(input("Enter n: "))
sum = 0
i=1
while i <= n:
sum = sum + i
i = i+1
print("The sum is", sum)

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

3.To print first 10 natural numbers


i=0
while i<=10:
print(i)
i=i+1

4. To print odd numbers from 1 to n


i=1
while i<=10:
if i%2==1:
print(i)
i=i+1
5.To check if the number is positive ,negative or zero and display using Nested if

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


if num >= 0:
if num == 0:
print("Zero")
else:
print("Positive number")
else:
print("Negative number")

6.To calculate discounted amount with discount %

original_price = float(input("Enter the original price: "))


discount_percent = float(input("Enter the discount percentage: "))
discount_amount = (original_price * discount_percent) / 100
discounted_price = original_price - discount_amount
print("Original Price: ", original_price)
print("Discount Percentage: ", discount_percent, "%")
print("Discount Amount: ", discount_amount)
print("Discounted Price: ", discounted_price)

7.Program to find the sum of all numbers stored in a list.

List=[11,12,13,14,15]
sum=0
for i in List:
sum=sum+i
print(sum)

8.To print the following patterns using multiple print commands


n=int(input(“Enter a number))
for i in range(1, n + 1):
print('*' * i)

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.

1) Create the list of students


students = ["John", "Alex", "Andrew", "Sam", "Nirav"]

2) Print the whole list


print("Original List:", students)
3) Add the name "Mahi" at the end
students.append("Mahi")

4) Remove the item at the second position.


students.pop(2)

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.

num = [23, 12, 5, 9, 65, 44]


print("Elements from second to fourth position:", num[1:4])
print("Elements from third to fifth position using negative indexing:", num[-4:-1])
print(“List in reverse order:”, num[::-1])

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)

You might also like