Sequential Programs

 1.      WAP to display sum of two integer numbers.

x = 2

y = 3

result = x+ y

print("The sum is:",result)

Output:

The sum is: 5

 

WAP to display sum of two integer numbers given by the user.

1.1

x = int(input("Enter the first number:"))

y = int(input("Enter the second number:"))

result = x+ y

print("The sum is:",result)

Output:

Enter the first number:2

Enter the second number:3

The sum is: 5

 1.2

x = int(input("Enter the first number:"))

y = int(input("Enter the second number:"))

result = x+ y

print(f"The sum of {x} and {y} is: {result}")

Output:

Enter the first number:2

Enter the second number:3

The sum of 2 and 3 is: 5

 

1.3

x = float(input("Enter first number:"))

y = float(input("Enter second number: "))

sum = x + y

print("The sum of {0} and {1} is {2}".format(x, y, sum))

Output:

Enter first number:2

Enter second number: 4.6

The sum of 2.0 and 4.6 is 6.6

 

2.      WAP to display product of two integer numbers given by the user

x = float(input("Enter first number:"))

y = float(input("Enter second number: "))

product = x * y

print("The product of {0} and {1} is {2}".format(x, y, product)).

Output:

Enter first number:2

Enter second number: 3

The product of 2.0 and 3.0 is 6.0

 

3.      To find the area of the rectangle (area = l*b)

x = float(input("Enter length:"))

y = float(input("Enter breadth: "))

area = x * y

print("The area of rectangle is",area)

Output:

Enter length:2.5

Enter breadth: 2

The area of rectangle is 5.0

 

4.      To display area and volume of a room(a=l*b             v=lbh)

l = float(input("Enter length:"))

b = float(input("Enter breadth: "))

h=float(input("Enter height: "))

area = l * b

volume=l*b*h

print("The area of room is",area)

print("The volume of room is",volume)

Output:

Enter length:2

Enter breadth: 3

Enter height: 4

The area of room is 6.0

The volume of room is 24.0

 

5.      To find simple interest.

p = float(input("Enter principle:"))

t = float(input("Enter time: "))

r=float(input("Enter rate: "))

si=(p*t*r)/100

print("simple interest=",si)

Output:

Enter principle:1000

Enter time: 3

Enter rate: 12

simple interest= 360.0

 

6.      To find average of three numbers

a = float(input("Enter first number:"))

b = float(input("Enter second number: "))

c=float(input("Enter third number: "))

avg=(a+b+c)/3

print("average=",avg)

Output:

Enter first number:2

Enter second number: 1

Enter third number: 5

average= 2.6666666666666665

 

7.      To convert degree Celsius and convert it into degree Fahrenheit where f=(9*c/5)+32.

c=float(input("Enter celsius: "))

f=(9*c/5)+32.

print("Fahrenheit =",f)

Output:

Enter celsius: 34

Fahrenheit = 93.2

 

8.      To find square of given number.

n=int(input("Enter a number: "))

s=n**2

print(f"square of {n} is =",s)

Output:

Enter a number: 2

square of 2 is = 4

 

9.      To find square root of given number.

n=int(input("Enter a number: "))

s=n**(1/2)

print(f"squareroot of {n} is =",s)

Output:

Enter a number: 4

squareroot of 4 is = 2.0

 

10.  To find cube root of given number.

n=int(input("Enter a number: "))

c=n**(1/3)

print(f"cuberoot of {n} is =",c)

Output:

Enter a number: 27

cuberoot of 27 is = 3


11.  To find the area of a circle .( a = (22/7)*r^2)

r = float(input("Enter radius:"))

area = (22/7)*(r**2)

print("The area of circle is",area)

Output:

Enter radius:2

The area of circle is 12.571428571428571

 

12.  To find the circumference of a circle.( c = 2*(22/7)*r)

r = float(input("Enter radius:"))

c = 2*(22/7)*r

print("circumference of circle is",c)

Output:

Enter radius:2

circumference of circle is 12.571428571428571

 

13.  To calculate volume of cylinder (v=π*r2h)

r = float(input("Enter radius:"))

h = float(input("Enter height:"))

v=(22/7)*r**2*h

print("volume of cylinder is",v)

Output:

Enter radius:2

Enter height:3

volume of cylinder is 37.714285714285715

 

14.  To convert minutes into hours and minutes.

m = int(input("Enter minute:"))

h = m//60

t=m % 60

print(f"{h} hour {t} minutes")

Output:

Enter minute:65

1 hour 5 minutes

 

15.  To input the number of days and convert it into years, months and days.

d = int(input("Enter days:"))

yr=d//365

d1=d % 365

m=d1//30

d2=d1 % 30

print(f"{yr} year {m} months {d2} days")

Output:

Enter days:430

1 year 2 months 5 days

 

Popular posts from this blog

Computer

Sequential Programs