I Puc Practical Python Programs
I Puc Practical Python Programs
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= "))
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")
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)