0% found this document useful (0 votes)
15 views10 pages

CP Assignment

The document contains 10 Python programs to perform basic mathematical calculations and conversions. The programs calculate the sum and average of numbers, the area of geometric shapes like triangles and rectangles, convert between Celsius and Fahrenheit temperatures, swap two numbers, and apply mathematical functions like ceil, round, and floor to floating point numbers. Each program is presented with its code, input, and output.

Uploaded by

soadabedinsiam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views10 pages

CP Assignment

The document contains 10 Python programs to perform basic mathematical calculations and conversions. The programs calculate the sum and average of numbers, the area of geometric shapes like triangles and rectangles, convert between Celsius and Fahrenheit temperatures, swap two numbers, and apply mathematical functions like ceil, round, and floor to floating point numbers. Each program is presented with its code, input, and output.

Uploaded by

soadabedinsiam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

1.

Write a python program to add two calculate the sum of two numbers :
Code:
x=float(input("Enter your 1st number:"))
y=float(input("Enter your 2nd number:"))
sum=x+y
print("sum of the two number is" , sum)
Output:
2.Write a python program to add two calculate the avarage of three
numbers :
Code:
x=float(input("1st number: "))
y=float(input("2nd number: "))
z=float(input("3rd number: "))
sum=x+y+z
avarage=sum/3
print("the avarage is " , avarage )
Output:
3.Write a python program to add two calculate the area of a triangle using
½*base*height:
Code:
x=float(input("Enter base of the triangle: "))
y=float(input("Enter height of the triangle:"))
area=0.5*x*y
print("the area of the triangle is=" , area)
Output:
4.Write a python program two calculate the area of a
triangle using three sides:
Code:
x = float(input("Enter the first side of the triangle: "))
y = float(input("Enter the second side of the triangle "))
z = float(input("Enter the trird side of the triangle "))
s = (x+y+z)/2
area = (s*(s-x)*(s-y)*(s-z))
print("the area of the triangle is = " , area)
Output:
5.Write a python program to calculate the area of a
rectangle:
Code:
length = float(input("Enter the length: "))
width = float(input("Enter width: "))
area= length*width
print("the area of the rectangle is = " , area)
Output:
6.Write a python program to calculate the area of a
circle:
Code:
radious = float(input("Enter the radious: "))
area= 3.1416*radious*radious
print("the area of the rectangle is = " , area)
Output:
7.write a python program to convert Celsius
temperature to Fahrenheit temperature:
Code:
c=float(input("temparature in celcius: "))
temparature_farenhite=(c*(9/5))+32
print("temparature in Farenhite is = " , temparature_farenhite)
Output:
8..write a python program to convert Fahrenheit
temperature to Fahrenheit Celsius:
Code:
f=float(input("temparature infarenhite: "))
temparature_celcius=(f-32)*(5/9)
print("temparature in Calcius is = " , temparature_celcius)
Output:
9.Write a python program to swap two numbers:

Code:
x=int(input("Enter 1st number:"))
y=int(input("Enter 2nd number:"))
x,y=y,x
print("1st number is" ,x)
print("2nd number is" ,y)
Output :
10.Write a python program to ceil , round and
floor a floating-point number:
Code:

x=float(input("Enter your floating number:"))

import math

a=math.ceil(x)
b=round(x)
c=math.floor(x)

print("ceil="+ str(a))
print("round="+ str(b))
print("floor=" + str(c))
Output:

You might also like