0% found this document useful (0 votes)
3 views

Assignment 3

Python

Uploaded by

rutujapawar.1408
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)
3 views

Assignment 3

Python

Uploaded by

rutujapawar.1408
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/ 4

8/10/24, 12:55 PM Assignment 3

Simple Basic Program

1. Write a program to calculate the area of a triangle given


the length of its three sides a, b and c
In [1]: a = float(input("Enter the length of side a: "))
b = float(input("Enter the length of side b: "))
c = float(input("Enter the length of side c: "))

Enter the length of side a: 5


Enter the length of side b: 3.4
Enter the length of side c: 7

In [2]: s = (a + b + c) / 2

In [3]: import math

In [6]: area = math.sqrt(s*(s-a)*(s-b)*(s-c))

In [7]: area

Out[7]: 7.910619444771695

 In [8]: print(f"The area of the triangle is: {area}")

The area of the triangle is: 7.910619444771695

2. Accept dimensions of a cylinder and print the surface area


and volume
In [9]: r = float(input("Enter the radius of cylinder: "))
h = float(input("Enter the height of cylinder: "))

Enter the radius of cylinder: 2.5


Enter the height of cylinder: 8

In [10]: surface_area = 2*math.pi*(r**2)+2*math.pi*r*h

In [11]: surface_area

Out[11]: 164.93361431346415

In [12]: volume = math.pi*(r**2)*h

In [13]: volume

Out[13]: 157.07963267948966

localhost:8888/notebooks/Desktop/FYBSc Python/Notes/Assignment 3.ipynb 1/4


8/10/24, 12:55 PM Assignment 3

In [14]: print(f"The surface area of the cylinder is: {surface_area}")


print(f"The volume of the cylinder is: {volume}")

The surface area of the cylinder is: 164.93361431346415


The volume of the cylinder is: 157.07963267948966

3. Accept three dimensions length (l), breadth(b) and


height(h) of a cuboid and print surface area and volume
(Hint: surface area=2(lb+lh+bh ), volume = lbh )
In [15]: l = float(input("Enter the length of cuboid: "))
b = float(input("Enter the breadth of cuboid: "))
h = float(input("Enter the height of cuboid: "))

Enter the length of cuboid: 6


Enter the breadth of cuboid: 4
Enter the height of cuboid: 5

In [16]: s_area = 2*(l*b+l*h+b*h)

In [17]: s_area

Out[17]: 148.0

In [18]: v = l*b*h

In [19]: v

Out[19]: 120.0

In [20]: print(f"The surface area of the cuboid is: {s_area}")


print(f"The volume of the cuboid is: {v}")

The surface area of the cuboid is: 148.0


The volume of the cuboid is: 120.0

4. Write a python program to calculate the distance between


two points.
In [21]: x1 = float(input("Enter the x-coordinate of the first point: "))
y1 = float(input("Enter the y-coordinate of the first point: "))
x2 = float(input("Enter the x-coordinate of the second point: "))
y2 = float(input("Enter the y-coordinate of the second point: "))

Enter the x-coordinate of the first point: 3


Enter the y-coordinate of the first point: -4
Enter the x-coordinate of the second point: 5
Enter the y-coordinate of the second point: 6

In [22]: distance = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)

In [23]: distance

Out[23]: 10.198039027185569

localhost:8888/notebooks/Desktop/FYBSc Python/Notes/Assignment 3.ipynb 2/4


8/10/24, 12:55 PM Assignment 3

In [24]: print(f"The distance between the points ({x1}, {y1}) and ({x2}, {y2}) is: {distance}"

The distance between the points (3.0, -4.0) and (5.0, 6.0) is: 10.198039027185569

5. Write a program to read the weight of an object in kilogram


and print its weight in pound and ton. [ Hint: 1 kg = 2.20
pound & 1kg = 0.001 ton]
In [25]: weight_kg = float(input("Enter the weight of the object in kilograms: "))

Enter the weight of the object in kilograms: 120

In [26]: weight_pound = weight_kg * 2.20

In [27]: weight_ton = weight_kg * 0.001

In [28]: print(f"The weight in pounds is: {weight_pound}")


print(f"The weight in tons is: {weight_ton}")

The weight in pounds is: 264.0


The weight in tons is: 0.12

6. Write a program to find area of rectangle.


In [29]: length = float(input("Length of a rectangle: "))
breadth = float(input("Breadth of a rectangle: "))

Length of a rectangle: 5.6


Breadth of a rectangle: 3.4

In [30]: area = length * breadth

In [31]: area

Out[31]: 19.04

In [32]: print(f"The area of rectangle is {area}")

The area of rectangle is 19.04

7. Write a program to calculate area and perimeter of the


square
In [33]: side = float(input("Side of sqaure is: "))

Side of sqaure is: 5.6

In [34]: area = side**2

localhost:8888/notebooks/Desktop/FYBSc Python/Notes/Assignment 3.ipynb 3/4


8/10/24, 12:55 PM Assignment 3

In [35]: area

Out[35]: 31.359999999999996

In [36]: perimeter = 4*side

In [37]: perimeter

Out[37]: 22.4

In [38]: print(f"The area of square is: {area}")


print(f"The perimeter of square is: {perimeter}")

The area of square is: 31.359999999999996


The perimeter of square is: 22.4

In [ ]: ​

localhost:8888/notebooks/Desktop/FYBSc Python/Notes/Assignment 3.ipynb 4/4

You might also like