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

file class ix

The document contains a series of Python programming exercises that cover various topics such as converting kilometers to meters, calculating simple interest, swapping numbers, and determining voting eligibility. Each exercise includes a code snippet, expected output, and user input examples. The exercises also demonstrate list manipulation and basic mathematical operations.

Uploaded by

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

file class ix

The document contains a series of Python programming exercises that cover various topics such as converting kilometers to meters, calculating simple interest, swapping numbers, and determining voting eligibility. Each exercise includes a code snippet, expected output, and user input examples. The exercises also demonstrate list manipulation and basic mathematical operations.

Uploaded by

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

Pr. 1 To convert length given in kilometers into meters.

Ans

km=int(input("enter the distance in km")


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

Output:
enter the distance in km10
Distance in meter is 10000

Pr. 2 Write a python code to calculate simple interest

p=int(input("Enter the principal amount"))


r=int(input("Enter the time"))
t=int(input("Enter the rate"))
SI=(p*r*t)/100
print("Simple interest is",SI)

Output
Enter the principal amount2000
Enter the time2
Enter the rate4
Simple interest is 160.0

Pr 3
Write a python code to swap two numbers

a=int(input("Enter the first number"))


b=int(input("Enter the second number"))
c=a
a=b
b=c
print("After swap a=",a,"b=",b)

Output
Enter the first number 20
Enter the second number65
After swap a= 65 b= 20

Pr 4
Wirte a python code to print m raised to power n by user

import math
m=int(input("Enter the first number"))
n=int(input("Enter the second number"))
k=math.pow(m,n)
print("Answer is",k)

Output
Enter the first number5
Enter the second number7
Answer is 78125.0
Pr 5
To calculate Area and Perimeter of a rectangle

l=int(input("Enter the length"))


b=int(input("Enter the breadth"))
pr=2*(l+b)
ar=l*b
print("Area is",ar)
print("perimeter is",pr)

Output
Enter the length20
Enter the breadth35
Area is 700
perimeter is 110

Pr6
To calculating percentage of students by entering marks of 3 subjects

m=int(input("Enter the marks in maths"))


s=int(input("Enter the marks in science"))
sst=int(input("Enter the marks in social science"))
total=m+s+sst
per=(total/300)*100
print("percentage is",per)
Output

Enter the marks in maths70


Enter the marks in science65
Enter the marks in social science68
percentage is 67.66

Pr 7

Write a program to check whether a person can vote or not

age=int(input("Enter the age"))


if age>=18:
print("You can vote")
else:
print("You cannot vote")

Output
Enter the age22
You can vote

Pr 8
Write a python code to check whether a number entered is odd or even
n=int(input("Enter the number"))
if n%2==0:
print("Number is even")
else:
print("Number is odd")

Output
Enter the number65
Number is odd
Pr 9
Write python code to calculate commission of salesman according to the following condition
Sale Commission
>=10000 10% of sales
>=5000 and <10000 8% of sales
<5000 6% of sales

s=int(input("Enter the sales"))


if s>=10000:
c=(10*s)/100
elif s>=5000 and s<10000:
c=(8*s)/100
else:
c=(5*s)/100
print("commission is",c)

Outptut
Enter the sales12000
commission is 1200.0

Enter the sales3000


commission is 150.0

Pr 10
Write a python code to print first n natural numbers using while loop

n=int(input("Enter the number"))


i=1
while i<=n:
print(i,end="\t")
i=i+1
Output
nter the number10
1 2 3 4 5 6 7 8 9 10

Q. 11 Write a python code to print sum of first n natural numbers

n=int(input("Enter the number"))


s=0
for i in range(1,n+1,1):
s=s+i
print("sum is",s)

Output
Enter the number10
sum is 55

Q. 12 Write python code to print factorial of a number


n=int(input("Enter the number"))
s=1
for i in range(1,n+1,1):
s=s*i
print("factorial is",s)

Output
Enter the number5
Factorial is 120
Q. 13 Write a python code to print number of a table

n=int(input("Enter the number"))


for i in range(1,11):
k=n*i
print(n,"*",i,"=",k)

Output
Enter the number6
6*1=6
6 * 2 = 12
6 * 3 = 18
6 * 4 = 24
6 * 5 = 30
6 * 6 = 36
6 * 7 = 42
6 * 8 = 48
6 * 9 = 54
6 * 10 = 60

Q,14 Create a list in Python of children selected for science quiz with following names-
Arjun, Sonakshi, Vikram, Sandhya, Sonal, Isha, Kartik
Perform the following tasks on the list in sequence-
○ Print the whole list
○ Delete the name “Vikram” from the list
○ Add the name “Jay” at the end
○ Remove the item which is at the second position.
l=["Arjun","Sonakshi","Vikram","Sandhya","Sonal","Isha","Kartik"]
print(l)
print(l.pop(2))
print(l.append("Jay"))
print(l.remove("Arjun"))

Output
['Arjun', 'Sonakshi', 'Vikram', 'Sandhya', 'Sonal', 'Isha', 'Kartik']
Vikram

Q. 15 Create a list num=[23,12,5,9,65,44]


○ print the length of the list
○ print the elements from second to fourth position using positive indexing
○ print the elements from position third to fifth using negative indexing

num=[23,12,5,9,65,44]
print(len(num))
print(num[2:5:1])
print(num[-5:-2])

Output
6
[5, 9, 65]
[12, 5, 9]

You might also like