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

I Puc Practical Python Programs

Uploaded by

ashishsinghc1983
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)
60 views

I Puc Practical Python Programs

Uploaded by

ashishsinghc1983
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/ 12

A1) Write a program to swap two numbers using a third variable.

Solution
x = 10
y = 50
print("Values of variables before swapping")
print("Value of x=", x)
print("Value of y=", y)
temp = x
x=y
y = temp
print("Values of variables after swapping")
print("Value of x=", x)
print("Value of y=", y)
A2) Write a python program to enter two integers and perform all arithmetic
operations on them.
Solution
num1 = int(input("Enter first number= "))
num2 = int(input("Enter second number= "))
print("The result for all arithmetic operations")
print("Sum= ",num1+num2)
print("Difference= ",num1-num2)
print("Product= ",num1*num2)
print("Quotient= ",num1/num2)
print("Modulus= ", num1%num2)
A3) Write a Python program to accept length and width of a rectangle and compute its
perimeter and area.
Solution
length = float(input("Enter length of the rectangle= "))
breadth = float(input("Enter breadth of the rectangle= "))
area = length * breadth
perimeter = 2 * (length + breadth)
print("Area of rectangle = ", area)
print("Perimeter of rectangle = ", perimeter)
A4) Write a Python program to calculate the amount payable if money has been lent on
simple interest. Principal = P, Rate of interest = R% per annum and Time = T years.
Then Simple Interest (SI) = (P x R x T)/ 100.
Amount payable = Principal + SI.
P, R and T are given as input to the program.
Solution
p = float(input(“Enter amount=”))
t = float(input(“Enter time=”))
r = float(input(“Enter rate=”))
si = (p*t*r)/100
print(“Simple interest=”,si)
A5) Write a Python program to find largest among three numbers.
Solution
num1 = float(input("Enter first number= "))
num2 = float(input("Enter second number= "))
num3 = float(input("Enter third number= "))

if (num1 >= num2) and (num1 >= num3):


largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
print("The largest number is", largest)
A6) Write a program that takes the name and age of the user as input and displays a
message whether the user is eligible to apply for a driving license or not. (the eligible age
is 18 years).
Solution
name = input("What is your name? ")
age = int(input("What is your age? "))

if age >= 18:


print("You are eligible to apply for the driving license.")
else:
print("You are not eligible to apply for the driving license.")
A8) Write a python program to find the grade of a student when grades are allocated as given in the
table below. Percentage of Marks Grade
Above 90% A
80% to 90% B
70% to 80% C
60% to 70% D
Below 60% E
Percentage of the marks obtained by the student is input to the program.
Solution
n = float(input(“Enter the percentage of the student=”))
if(n > 90):
print("Grade A")
elif(n > 80):
print("Grade B")
elif(n > 70):
print("Grade C")
elif(n >= 60):
print("Grade D")
else:
print("Grade E")
A9) Write a python program to print the table of a given number. The number has to be
entered by the user
Solution
num = int(input("Enter the number= "))
count = 1
while count <= 10:
prd = num * count
print(num, 'x', count, '=', prd)
count += 1
A10) Write a program to find the sum of digits of an integer number, input by the user
Solution
sum = 0
n = int(input("Enter the number: "))
while n > 0:
digit = n % 10
sum = sum + digit
n = n//10
print("The sum of digits of the number is",sum)
B1) Write a program that uses a user defined function that accepts name and gender
(as M for Male, F for Female) and prefixes Mr/Ms on the basis of the gender.

def prefix(name,gender):
if (gender == 'M' or gender == 'm'):
print("Hello, Mr.",name)
elif (gender == 'F' or gender == 'f'):
print("Hello, Ms.",name)
else:
print("Please enter only M or F in gender")

name = input("Enter your name= ")


gender = input("Enter your gender: M for Male, and F for Female: ")
prefix(name,gender)
B4) Write a python program to input line(s) of text from the user until enter is pressed. Count the
total number of characters in the text (including white spaces),total number of alphabets, total
number of digits, total number of special symbols and total number of words in the given text.
(Assume that each word is separated by one space).
Solution
userInput = input("Write a sentence= ")
totalChar = len(userInput)
print("Total Characters: ",totalChar)
totalAlpha = totalDigit = totalSpecial = 0
for a in userInput:
if a.isalpha():
totalAlpha += 1
elif a.isdigit():
totalDigit += 1
else:
totalSpecial += 1
print("Total Alphabets= ",totalAlpha)
print("Total Digits= ",totalDigit)
print("Total Special Characters= ",totalSpecial)

totalSpace = 0
for b in userInput: if
b.isspace():
totalSpace += 1
print("Total Words in the Input =",(totalSpace + 1))
B7) Write a python program to find the number of times an element occurs
in the list.

list1 = [10, 20, 30, 40, 50, 60, 20, 50, 10, 30, 50, 30, 24, 45]
print("The list is=",list1)
inp = int(input("Which element occurrence would you like to count? "))
count = list1.count(inp)
print("The count of element in the list =",count)

You might also like