S.
Practical Assignment
No.
1
Write a program that generates the following outputs:
5
10
9
Assign value 5 to a variable using assignment operator (=). Multiply it
with 2 to generate 10 and subtract 1 to generate 9.
CODE:
a=5
print(a,)
b=a*2
print(b,)
c=b-1
print(c,)
OUTPUT:
5
10
9
3
Write a python program that accepts radius of a circle and prints
its area.
CODE:
r=int(input("enter a value for radius "))
a=3.14*r**2
print("The area of the circle is",a,)
OUTPUT:
enter a value for radius 13
The area of the circle is 615.44
4
Write a python program that accepts marks in 5 subjects and
outputs average marks.
CODE:
m=int(input("enter your marks for math "))
s=int(input("enter your marks for science "))
e=int(input("enter your marks for english "))
h=int(input("enter your marks for hindi "))
c=int(input("enter your marks for computer "))
a=(m+s+e+h+c)/5
print("The average marks are",a,)
OUTPUT:
enter your marks for math 49
enter your marks for science 49
enter your marks for english 49
enter your marks for hindi 49
enter your marks for computer 49
The average marks are 49
5
Write a program to read a number n and print n2, n3 and n4.
CODE:
n=int(input("enter a number "))
a=n**2
b=n**3
c=n**4
print("the square is",a,"the cube is",b,"power to 4 is",c,)
OUTPUT:
enter a number 4
the square is 16 the cube is 64 power to 4 is 256
6 Write a program to compute simple interest and compound
interest.
CODE:
p=int(input("enter the principle amount"))
r=int(input("enter the rate"))
t=int(input("enter the time"))
si=p*r*t*100
print("the simple interest is",si,)
OUTPUT:
enter the principle amount 20000
enter the rate 10
enter the time 5
the simple interest is 100000000
7 Write a program to read details like name, class, age of a student
and then print the details firstly in same line and then in separate
lines.
CODE:
n=input("enter your name ")
c=input("enter your class ")
a=input("enter your age ")
print(n,c,a,)
print(" ")
print(n,)
print(c,)
print(a,)
OUTPUT:
enter your name priya
enter your class 9
enter your age 15
Priya 9 15
Priya
9
15
CH CODE:
2
#1 Create a list namely test having at least 3
integers, 2 floating point numbers and 2 strings.
test = [-21, -3, 9, 9.4, 2.7, "shrutis27", "shruts9"]
#2 Print the first element from the list test.
print (test[0])
#3 Print the last element from the list test.
print(test[6])
#4 Print the second element from the list test.
print(list[1])
#5 Print the second last element form the list
test.
print(test[5])
#6 Print the third element and the third last from
the list.
print(test[2])
print(test[4])
#7 Print all the element from the list test.
print(test)
#8 Print the size of the list test now.
len(test)
#9 Add element “ditto” to the list test.
[Link]("ditto")
#10 Print the size of the list test now.
len(test)
#11 Print the last element from the list test.
print(test[-1])
#12 Print the second last element from the list
test.
print(test[-2])
#13 Modify the second last element of the list
test as “new”.
test[-2]="new"
#14 Print the size of the list test now.
len(test)
OUTPUT:
-21
Priya2
list[1]
Priya22
9
2.2
[-22, -2, 9, 9.4, 2.2, 'priya2', ‘priya22']
ditto
Priya2