Computer Practical
Computer Practical
RESULT:
RESULT:
Enter weight in kg : 66
Enter height in meters : 1.6
BMI is : 25.781249999999996
QUE: WRITE A PROGRAM TO INPUT A VALUE IN
TONNES AND CONVERT IT INTO QUINTALS AND
KILOGRAMS
(1-tonne = 10 quintals , 1- tonne = 1000 kgs, 1 quintal = 100
kgs)
print("Tonnes:",tonnes)
print("Quintals :", quintals)
print("Kilograms:",kgs)
RESULT:
Enter tonnes: 2.5
Tonnes: 2.5
Quintals: 25.0
Kilograms: 2500.0
QUE: WRITE A PROGRAM TO ENTER TWO INTEGERS
AND PERFORM ALL ARITHMETIC OPERATORS ON
THEM.
x = int(input("Enter value1:"))
y = int(input("Enter value2:"))
summ = x + y
diff = x - y
mult = x * y
div = x / y
mod = x % y
print("Numbers are :", x,y)
print("Sum = ", summ)
print("Difference = ", diff)
print("Product = ", mult)
print("Division = ", div)
print("Modulus = ", mod)
RESULT:
Enter value1: 7
Enter value2: 3
Numbers are: 7 3
Sum = 10
Difference = 4
Product = 21
Division = 2.3333333333333335
QUE: WRITE A PROGRAM TO SWAP TWO NUMBERS
USING A THIRD VARIABLE.
t = x
x = y
y = t
print("After Swapping, Numbers are :", x,y)
RESULT:
Enter value1 : 6
Enter value2 : 9
Original Numbers are : 6 9
After Swapping, Numbers are : 9 6
QUE: THE RADIUS OF A SPHERE IS 7.5 METERS.
WRITE PYTHON SCRIPT TO CALCULATE ITS AREA
AND VOLUME.
(Area of a sphere = πr2, Volume of a sphere = 4πr3)
import math
r = 7.5
area = math.pi * r * r
volume = 4 * math.pi * math.pow(r,3)
RESULT:
RESULT:
import math
a, b, c = 17, 23, 30
s = (a + b + c)/2
area = math.sqrt(s * (s-a) * (s-b) * (s-c) )
RESULT:
Sides of triangle : 17 23 30
Area: 194.42222095223582 units square
QUE: PROGRAM TO FIND THE MULTIPLES OF A
NUMBER
( the divisor) OUT OF THE GIVEN FIVE NUMBERS.
RESULT:
import math
print("For quadratic equation, ax**2 + bx + c = 0, enter
cofficients below")
a = int(input("Enter a :"))
b = int(input("Enter b :"))
c = int(input("Enter c :"))
if a==0 :
print("Value of",a,'should not be zero')
print("\n Aborting !!!!!!")
else :
delta = b * b-4 * a * c
if delta > 0 :
root1 = (-b + math.sqrt(delta)) / (2*a)
root2 = (-b - math.sqrt(delta)) / (2*a)
print ("Roots are REAL and UNEQUAL")
print ("Root1 =", root1,", Root2=", root2)
elif delta ==0:
root1 =-b / (2*a) ;
print("Roots are REAL and EQUAL")
print ("Root1 =", root1,", Root2=",root1)
else :
print ("Roots are COMPLEX and IMAGINARY”)
RESULT:
first = 0
second = 1
print (first)
print (second)
for a in range (1, 19) :
third = first + second
print (third)
first, second = second, third
RESULT:
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
QUE: NUMBERS IN THE FORM 2n – 1 ARE CALLED
MERSENNE NUMBERS, e.g.,
21 – 1 = 1, 22 – 1 = 3, 23 – 1 = 7.
WRITE A PYTHON SCRIPT THAT DISPLAYS FIRST TEN
MERSENNE NUMBERS.
RESULT:
RESULT:
1
1 3
1 3 5
1 3 5 7
QUE: WRITE A PROGRAM TO PRINT A UNIQUE
PATTERN:
n = 5 # number of lines
s = n * 2 - 1 # for initial spaces
for i in range(1, n + 1) :
for j in range(0, s) :
print(end = " ")
for j in range(i, 0, -1):
print(j,end = " ")
for j in range(2, i+1) :
print(j, end =" ")
s = s - 2
print()
RESULT:
1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
QUE: WRITE A PROGRAM THAT READS A STRING AND
CHECKS WHETHER IT IS A PALINDROME STRING OR
NOT WITHOUT USING STRING SLICE.
RESULT: