Câu 3: Để tính toán chu vi/chu vi và diện tích hình dạng như & nbsp; Tam giác, hình chữ nhật, hình vuông và vòng tròn.To calculate perimeter/circumference and area of shapes such as triangle, rectangle, square and circle.
#We sẽ sử dụng các hàm Python do người dùng xác định cho nhiệm vụ này.
#we sẽ nhập thư viện toán học để sử dụng sqrt (), điều này sẽ được sử dụng để #calculation root.
Nhập MathDef Area_Square (A): & NBSP; & nbsp; khu vực1 = float (a*a); & nbsp; & nbsp; in ("Khu vực hình vuông là:", khu vực1) DEF Area_circle (r): & nbsp; & nbsp; khu vực2 = float (3.14*r*r); & nbsp; & nbsp; in ("Khu vực của vòng tròn là:", khu vực2) DEF Area_Rectangle (a, b): & nbsp; & nbsp; khu vực3 = float (a*b); & nbsp; & nbsp; in ("diện tích hình chữ nhật là:", khu vực3) def area_triangle (x, y): & nbsp; & nbsp; khu vực4 = float ((x*y)/2); & nbsp; & nbsp; in ("Khu vực tam giác là:", khu vực4) def peri_square (a): & nbsp; & nbsp; peri1 = float (4*a); & nbsp; & nbsp; in ("chu vi của hình vuông là:", peri1) def peri_circle (r): & nbsp; & nbsp; peri2 = float (2*3.14*r); & nbsp; & nbsp; in ("Perimter of Circle là:", peri2) def peri_triangle (a, b): & nbsp; & nbsp; hypotenuse = float (math.sqrt (a*a+b*b)) & nbsp; & nbsp; peri3 = float (a+b+hypotenuse) & nbsp; & nbsp; in ("Perimter của tam giác góc phải là:", peri3) def peri_rectangle (a, b): & nbsp; & nbsp; peri4 = float (2*(a+b)) & nbsp; & nbsp; print ("Perimter của hình chữ nhật là:", peri4) side = float (input ("vào bên của hình vuông:")) Circle: ")) Area_circle (Bán kính) Peri_Circle (Bán kính) Độ dài = Float (Input (" Nhập chiều dài của hình chữ nhật: ")) ) peri_rectangle (chiều dài, chiều rộng) cơ sở = float (đầu vào ("nhập cơ sở của tam giác góc vuông:")) chiều cao = float (đầu vào ("vào chiều cao của tam giác góc vuông:")) (cơ sở, chiều cao) Mã nguồn:
def
area_square(a):
area1=float(a*a);
print("Area of square is:",area1)
def area_circle(r):
area2=float(3.14*r*r);
print("Area of circle is:",area2)
def area_rectangle(a,b):
area3=float(a*b);
print("Area of rectangle is:",area3)
def area_triangle(x,y):
area4=float((x*y)/2);
print("Area of triangle is:",area4)
def peri_square(a):
peri1=float(4*a);
print("Perimeter of square is:",peri1)
def peri_circle(r):
peri2=float(2*3.14*r);
print("Perimter of circle is:",peri2)
def peri_triangle(a,b):
hypotenuse=float(math.sqrt(a*a+b*b))
peri3=float(a+b+hypotenuse)
print("Perimter of right angled triangle is:",peri3)
def peri_rectangle(a,b):
peri4=float(2*(a+b))
print("Perimter of rectangle is:",peri4)
side=float(input("enter the side of square:"))
area_square(side)
print()
peri_square(side)
radius=float(input("enter the radius of circle:"))
area_circle(radius)
peri_circle(radius)
length=float(input("enter the length of rectangle:"))
breadth=float(input("enter the breadth of rectangle:"))
area_rectangle(length,breadth)
peri_rectangle(length,breadth)
base=float(input("enter the base of right angled triangle:"))
height=float(input("enter the height of right angled triangle:"))
area_triangle(base,height)
peri_triangle(base,height)
Source Code:
Chương trình Python đã điều chỉnh chu vi/chu vi và diện tích hình dạng như hình tam giác, hình chữ nhật, hình vuông và vòng tròn. calculate perimeter/circumference and area of shapes such as triangle, rectangle, square and circle. |
Chương trình Python để tính toán chu vi/chu vi và diện tích hình dạng như hình tam giác, hình chữ nhật, hình vuông và hình tròn. |
Output:
Đầu ra |
# Python progam to calculate perimeter/circumference and area of shapes such as trinagle, rectangle, square and circle print("Enter number to select shape:") print("1.Triangle") print("2.Rectangle") print("3.Square") print("4.Circle") n = int(input("Enter your choice 1,2,3,4 :")) if (n==1): S1 = int(input("Enter the length of Side 1 :")) S2 = int(input("Enter the length of Base :" )) S3 = int(input("Enter the length of Side 3 :")) h = int(input("Enter the height of the triangle : ")) print ("Perimeter of trinagle is ",(S1+S2+S3)) print ("Area of triangle is ",(1/2*S2*h)) elif (n==2): l = int(input("Enter the length of the rectangle : ")) b = int(input("Enter the base of the rectangle : ")) print("Perimeter of the rectangle is : ",(2*(l+b))) print("Area of the rectangle is : ",(l*b)) elif(n==3): s = int(input("Enter the length of the side of square : ")) print("Perimeter of square is ",(4*s)) print("Area of square is ",(s*s)) elif(n==4): r = int(input("Enter the radius of the circle : ")) print("Circumference of the circle is ",(2*3.14*r)) print("Area of the circle is ",(3.14*r*r)) else: print("Invalid Option")
Đầu ra
(Run the program to view its output)