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

Practical File

Uploaded by

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

Practical File

Uploaded by

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

PYTHON PROGRAMS

CLASS – XI
PRACTICAL FILE – INFORMATICS PRACTICES
1. Write a program to obtain three numbers and print their sum.
Solution:
num1 = int( input ("Enter number 1 : "))
num2 = int( input("Enter number 2 : "))
num3 = int( input ("Enter number 3 : "))
Sum = num1 + num2 + num3
print(“Sum is :” Sum)
OUTPUT:
Enter number 1 : 1
Enter number 2 : 2
Enter number 3 : 3
Sum is : 6

2. Write a program to obtain length and breadth of a rectangle and calculate its area.
Solution:
length = float( input ("Enter length of the rectangle: "))
breadth = float( input ("Enter breadth of the rectangle: "))
area = length * breadth
print("Length=", length)
print("Breadth=", breadth)
print("Area=", area)

OUTPUT:
Enter length of the rectangle: 8.5
Enter breadth of the rectangle: 35
Length= 8.5
Breadth= 35.0
Area= 297.5
3. Write a program to input a number and print its cube.
Solution:
num=int(input("Enter a number:"))
cube=num*num*num
print("Number is:",num)
print("Cube is:",cube)
OUTPUT:
Enter a number: 5
Number is: 5
Cube is: 125
4. Write a program to input a value in kilometeres and convert into miles. (1 km = 0.621371
miles)
Solution:
km = int( input ("Enter kilometres : "))
miles = km * 0.621371
print("Kilometres :", km)
print("Miles : ", miles)
OUTPUT:
Enter kilometres : 15
Kilometres : 15
Miles : 9.320565
5. Write a program to calculate simple interest.
Solution:
principal_amt = float(input('Enter amount: '))
time = float(input('Enter time: '))
rate = float(input('Enter rate: '))
simple_interest = (principal_amt*time*rate)/100
print('Simple interest is:',simple_interest)
OUTPUT:
Enter amount: 200000
Enter time: 2
Enter rate: 5.5
Simple interest is: 22000.0
6. Write a program to obtain temperature in Celsius and convert into Fahrenheit using the
formula: F= C*9/5+32
Solution:
cels = float (input ("Enter temp in Celsius :"))
print ("Temperature in Celsius is : ", cels)
f = cels * 9/5 + 32
print ("Temperature in Fahrenheit is : ", f)
OUTPUT:
Enter temp in Celsius :37
Temperature in Celsius is : 37.0
Temperature in Fahrenheit is : 98.6

7. Write a program to check whether the given number is odd or even.


Solution:
num = int(input('enter an integer:'))
if num%2 ==0:
print(num,'is even number')
else:
print(num,'is odd number')
OUTPUT:
enter an integer:25
25 is odd number

8. Write a program to input age and check it is eligible for vote or not.
Solution:
age=int(input(‘Enter your age:’))
if age>=18:
print(‘Eligible to vote’)
else:
print(‘It is not eligible’)

OUTPUT:
Enter your age:25
Eligible to vote
9. Write a program to print a table of number of 5.

Solution:
num=5
for i in range(1,11,1):
print(num,'x',i,'=',num*i)

OUTPUT:
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50

10. Write a program to swap two numbers without temporary variable.


Solution:

num1 = input('Enter First Number: ')


num2 = input('Enter Second Number: ')
print("Value of num1 before swapping: ", num1)
print("Value of num2 before swapping: ", num2)
# swapping two numbers without using temporary variable
num1, num2 = num2, num1
print("Value of num1 after swapping: ", num1)
print("Value of num2 after swapping: ", num2)

OUTPUT:
Enter First Number: 10
Enter Second Number: 20
Value of num1 before swapping: 10
Value of num2 before swapping: 20
Value of num1 after swapping: 20
Value of num2 after swapping: 10
11. Write a program to input three integers and print the largest of the three.
Solution:
x=y=z=0
x= int (input("Enter first number :" ) )
y = int (input ( "Enter second number :" ) )
z = int (input("Enter third number :" ) )
max = x
if y > max :
max = y
if z > max :
max=z
print ("Largest number is", max)
OUTPUT:
Enter first number :25
Enter second number :30
Enter third number :63
Largest number is 63

12. Write a program to accept percentage from the user and display the grade according to
the following criteria:

Marks Grade
> 90 A
> 80 and <= 90 B
>= 60 and <= 80 C
below 60 D

Solution:
per = int(input("Enter marks"))
if per > 90:
print("Grade is A")
if per > 80 and per <=90:
print("Grade is B")
if per >=60 and per <= 80:
print("Grade is C")
if per < 60:
print("Grade is D")
OUTPUT:
Enter marks56
Grade is D

13. Write a program to create a list of any five colour names which has taken by user.
Solution:

a=[]

for i in range(5):

cl=input("Enter name of any color")

a.append(cl)

print(a)

OUTPUT:

Enter name of any color blue

Enter name of any colorblack

Enter name of any colorred

Enter name of any coloryellow

Enter name of any colorpink

[' blue', 'black', 'red', 'yellow', 'pink']

14. Write a program in python which removes the last element from the list and insert it in
the beginning.
List : L = [1, 3, 2, 34, ‘amit’, 7, 5]

Solution:

L = [1, 3, 2, 34, 'amit', 7, 5]

L.insert(0, L.pop())

print(L)

OUTPUT:

[5, 1, 3, 2, 34, 'amit', 7]


15. Write a program to show the keys and values of dictionary.
Solution:
dict = {'Anil':50000, 'Mukesh':60000, 'Dinesh': 65000}
print(dict.keys())
print(dict.values())

OUTPUT:
dict_keys(['Anil', 'Mukesh', 'Dinesh'])
dict_values([50000, 60000, 65000])

16. Program to check whether a person is eligible to vote or not.


Solution:
age = int (input("Enter your age? "))
if age>=18:
print("You are eligible to vote !!");
else:
print("Sorry! you have to wait !!");

OUTPUT:
Enter your age? 18
You are eligible to vote!!

17. The record of a student (Name, Roll No., Marks in five subjects and percentage of marks)
is stored in the following list:
Rec = [ ‘Raman’, ‘A-36’, [56,98,99,72,69], 78.8]
Write python statement to retrieve the following information from the list rec.
(a) Percentage of the student

(b) Marks in the fifth subject

(c) Maximum marks of the student

(d) Roll no. of the student


(e) Change the name of the student from ‘Raman’ to ‘Raghav’

OUTPUT:
(a) >>> rec[3]
78.8

(b) >>> rec[2] [4]


69

(c) >>> max(rec[2])


99

(d) >>> rec[1]


‘A-36’

(e) >>> rec [0] = “Raghav”

18. Write a program to find the number of times an element occurs in the list.

Solution:

val = eval(input(“Enter a list:”))

item = int(input(“Enter element:”))

print(item, “occurs in the list”, val.count(item), “times.”)

OUTPUT:

Enter a list: [1,3,4,2,1,4,1]

Enter element: 1

1 occurs in the list 3 times.

19. Write a program to print triangle of stars.

Solution:

for i in range(1,5):
for j in range(i):
print('*',end='')
print()

20. Write a program through loop to find maximum value in list.

Solution:

numbers = [1,4,50,80,12]
max = 0
for n in numbers:
if(n>max):
max = n
print(max)

OUTPUT:

80

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy