Class - Ix Practicals Python
Class - Ix Practicals Python
# PROGRAM-2 : Write a program to obtain temperature in Celsius and convert it into Fahrenheit using formula
Ans Code:
cels=float(input("enter temp in celsius:"))
print ("Temprature in celsius is:",cels)
Farh = cels*9/5+32
print ("Temprature in fahrenheit is:",Farh)
OUTPUT-
# PROGRAM-3 : Program to obtain length and breadth of a rectangle and calculate its area.
Ans Code:
length= float(input("Enter length of the rectangle:"))
breadth= float(input("Enter breadth of the rectangle:"))
area = length * breadth
print("Rectangle specifications")
print("length=",length)
print("breadth=",breadth)
print("area=",area)
OUTPUT-
# PROGRAM-4 : Write a python program that accepts radius of a circle and prints its area.
Ans Code:
radius = float(input("Enter radius of circle: "))
area = 3.14159 * radius * radius
print("Area of circle =", area)
OUTPUT-
# PROGRAM-5 : Write a python program that accepts marks in 5 subjects and outputs average marks.
Ans Code:
m1 = int(input("Enter first subject marks: "))
m2 = int(input("Enter second subject marks: "))
m3 = int(input("Enter third subject marks: "))
m4 = int(input("Enter fourth subject marks: "))
m5 = int(input("Enter fifth subject marks: "))
avg = (m1 + m2+ m3+ m4 + m5) / 5;
print("Average Marks =", avg)
OUTPUT-
# PROGRAM-6 : Write a python program to compute simple interest and compound interest.
Ans Code:
p = float(input("Enter principal: "))
r = float(input("Enter rate: "))
t = int(input("Enter time: "))
si = (p * r * t) / 100
ci = p * ((1 + (r / 100 ))** t) - p
print("Simple interest = ", si)
print("Compound interest = ", ci)
OUTPUT-
# PROGRAM-7 : Write a python program to read details like name, class, age of a student and then print details firstly
in same line and then in separate lines.
Ans Code:
n = input("Enter name of student: ")
c = int(input("Enter class of student: "))
a = int(input("Enter age of student: "))
print("Name:", n, "Class:", c, "Age:", a)
print()
print()
print("Name:", n)
print("Class:", c)
print("Age:", a)
OUTPUT-
# PROGRAM-8: Take the list --- animals = [‘cat’, ’dog’, ’mouse’ ,’hamster’]
ii) Print the first animal in the animals list.(with using positive index)
iii) Print the last animal in the animals list (with using negative index)
Ans Code:
animals = [‘cat’, ’dog’, ’mouse’ ,’hamster’]
for one in animals:
print(one)
print (animals[0]) #first element
size = len(animals)
print(animals[-1]) #last element
OUTPUT-
# PROGRAM-9: Take the list --- animals = [‘cat’, ’dog’, ’mouse’ ,’hamster’]
ii) Print the first animal in the animals list.(with using negative index)
iii) Print the last animal in the animals list (with using positive index)
Ans Code:
animals = [‘cat’, ’dog’, ’mouse’ ,’hamster’]
for one in animals:
print(one)
size = len(animals)
print (animals[-size]) #first element
print(animals[size-1]) #last element
# PROGRAM- 10 Create a list namely test having at least 3 integers, 2 floating point numbers and two strings.
Ans Code:
test=list((2,5,7,9.8,7.6,"apple","kiwi"))
print(test)
print(test[0]) #first element
print(test[-1]) #last element
print(test[1]) #2nd element