Python có điều kiện: Bài tập - 36 với giải pháp
Viết một chương trình Python để kiểm tra một tam giác là công bằng, isosceles hoặc scalene. Lưu ý: Một tam giác đều là một tam giác trong đó cả ba cạnh đều bằng nhau. Một tam giác scalene là một tam giác có ba mặt không đồng đều. Một tam giác cân là một tam giác với [ít nhất] hai cạnh bằng nhau.
Note :
An equilateral triangle is a triangle in which all three sides are equal.
A scalene triangle is a triangle that has three unequal sides.
An
isosceles triangle is a triangle with [at least] two equal sides.
Trình bày bằng hình ảnh:
Giải pháp mẫu:
Mã Python:
print["Input lengths of the triangle sides: "]
x = int[input["x: "]]
y = int[input["y: "]]
z = int[input["z: "]]
if x == y == z:
print["Equilateral triangle"]
elif x==y or y==z or z==x:
print["isosceles triangle"]
else:
print["Scalene triangle"]
Đầu ra mẫu:
x: 6 y: 8 z: 12 Scalene triangle
Sơ đồ :
Trực quan hóa thực thi mã Python:
Công cụ sau đây trực quan hóa những gì máy tính đang làm từng bước khi nó thực hiện chương trình đã nói:
Trình chỉnh sửa mã Python:
Có một cách khác để giải quyết giải pháp này? Đóng góp mã của bạn [và nhận xét] thông qua Disqus.
Trước đây: Viết chương trình Python để kiểm tra một chuỗi đại diện cho một số nguyên hay không? Tiếp theo: Viết một chương trình Python đọc hai số nguyên đại diện cho một tháng và ngày và in mùa cho tháng đó.
Write a Python program to check a string represent an integer or not?
Next: Write a Python program that reads two integers representing a month and day and prints the season for that month and day.
Python: Lời khuyên trong ngày
Số nguyên, phao, dây, booleans và bộ dữ
Khi chúng ta gán một biến cho một loại bất biến như số nguyên, phao, chuỗi, booleans và bộ dữ liệu, thì biến này chỉ vào một đối tượng trong bộ nhớ.
Trong trường hợp chúng tôi gán cho biến đó, một giá trị khác, đối tượng gốc vẫn còn trong bộ nhớ, nhưng biến chỉ vào nó bị mất:
number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 4325215472
Tham khảo: //bit.ly/3ndmjen
n = int [input []].
Làm thế nào để bạn tìm thấy tam giác isosceles trong Python?
Mã tam giác isosceles trong Python.
n = int [input []].
Làm thế nào để bạn tìm thấy tam giác isosceles trong Python?
Mã tam giác isosceles trong Python.
In ["Chiều dài đầu vào của các cạnh tam giác:"].X, Y, and Z representing the three sides of a triangle, the task is to check whether the triangle formed by the given sides is equilateral, isosceles, or scalene.
x = int [đầu vào ["x:"]]. A triangle is said to be equilateral triangle if all the sides are equal. If X, Y, Z are three sides of the triangle. Then, the triangle is equilateral only if X = Y = Z.
y = int [đầu vào ["y:"]]. A triangle is said to be an isosceles triangle if any of its two sides are equal. If X, Y, Z are three sides of the triangle.Then, the triangle is isosceles if either X = Y or X = Z or Y = Z.
z = int [đầu vào ["z:"]]. A triangle is said Scalene Triangle if none of its sides is equal.
Examples:
Nếu x == y == z:. X = 6, Y = 8, Z = 10
Output: Scalene Triangle
Explanation:
Since all the sides of the given triangle are unequal, the triangle is scalene.In ["Tam giác cân bằng"]. X = 10, Y = 10, Z = 10
Output: Equilateral Triangle
Explanation:
Since all the sides of the given triangle are equal.
Elif x == y hoặc y == z hoặc z == x:. Follow the steps below to solve the problem:
- Công thức cho tam giác trong Python là gì?X = Y and Y = Z. If found to be true, print “Equilateral Triangle”.
- s = [a + b + c] / 2. # Tính diện tích. diện tích = [s*[s-a]*[s-b]*[s-c]] ** 0,5. in ['diện tích của tam giác là %0,2f' %diện tích]X = Y or X = Z or Y = Z. If found to be true, print “Isosceles Triangle”.
- Xem thảo luận
Cải thiện bài viết
C++
#include
Lưu bài viết
Đọc
x: 6 y: 8 z: 12 Scalene triangle5
x: 6 y: 8 z: 12 Scalene triangle9
x: 6 y: 8 z: 12 Scalene triangle11
x: 6 y: 8 z: 12 Scalene triangle1229____29
x: 6 y: 8 z: 12 Scalene triangle14
x: 6 y: 8 z: 12 Scalene triangle9
number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 43252154720
number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 43252154721
number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 43252154722
x: 6 y: 8 z: 12 Scalene triangle03
x: 6 y: 8 z: 12 Scalene triangle04
checkTriangle[
9x: 6 y: 8 z: 12 Scalene triangle9
number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 43252154720
number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 43252154729
number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 43252154722
x: 6 y: 8 z: 12 Scalene triangle6
number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 43252154724
x: 6 y: 8 z: 12 Scalene triangle9
number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 43252154720
#include
5number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 43252154722
#include
7
int
#include
9
x: 6 y: 8 z: 12 Scalene triangle5
x: 6 y: 8 z: 12 Scalene triangle6
int
using
3x: 6 y: 8 z: 12 Scalene triangle6
using
5#include
7
Java
using
7 using
8
using
9 void
x: 6 y: 8 z: 12 Scalene triangle5
x: 6 y: 8 z: 12 Scalene triangle6
x: 6 y: 8 z: 12 Scalene triangle7
std;
1x: 6 y: 8 z: 12 Scalene triangle9
std;
3number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 43252154721
std;
5x: 6 y: 8 z: 12 Scalene triangle6
number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 43252154724
x: 6 y: 8 z: 12 Scalene triangle7
std;
9x: 6 y: 8 z: 12 Scalene triangle9
std;
3number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 43252154729
std;
5x: 6 y: 8 z: 12 Scalene triangle6
number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 43252154724
x: 6 y: 8 z: 12 Scalene triangle9
std;
3#include
5std;
5#include
7
checkTriangle[
1 using
9 void
checkTriangle[
4
x: 6 y: 8 z: 12 Scalene triangle5
x: 6 y: 8 z: 12 Scalene triangle6
int
checkTriangle[
8checkTriangle[
9int
0int
1____92x: 6 y: 8 z: 12 Scalene triangle6
using
5#include
7
#include
7
Python3
int
9
x: 6 y: 8 z: 12 Scalene triangle00
x: 6 y: 8 z: 12 Scalene triangle6
x: 6 y: 8 z: 12 Scalene triangle7
x: 6 y: 8 z: 12 Scalene triangle03
x: 6 y: 8 z: 12 Scalene triangle044____104
x: 6 y: 8 z: 12 Scalene triangle9
x: 6 y: 8 z: 12 Scalene triangle11
x: 6 y: 8 z: 12 Scalene triangle12
number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 43252154721
x: 6 y: 8 z: 12 Scalene triangle14
Is
x: 6 y: 8 z: 12 Scalene triangle9
x: 6 y: 8 z: 12 Scalene triangle11
x: 6 y: 8 z: 12 Scalene triangle1229____29
x: 6 y: 8 z: 12 Scalene triangle14
x: 6 y: 8 z: 12 Scalene triangle6
number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 43252154724
x: 6 y: 8 z: 12 Scalene triangle38
x: 6 y: 8 z: 12 Scalene triangle9
x: 6 y: 8 z: 12 Scalene triangle11
x: 6 y: 8 z: 12 Scalene triangle12
#include
5x: 6 y: 8 z: 12 Scalene triangle14
x: 6 y: 8 z: 12 Scalene triangle03
x: 6 y: 8 z: 12 Scalene triangle04
checkTriangle[
9x: 6 y: 8 z: 12 Scalene triangle06
x: 6 y: 8 z: 12 Scalene triangle04
int
1x: 6 y: 8 z: 12 Scalene triangle25
x: 6 y: 8 z: 12 Scalene triangle04
int
3x: 6 y: 8 z: 12 Scalene triangle53
C#
using
x: 6 y: 8 z: 12 Scalene triangle55
using
7 using
8
using
9 void
x: 6 y: 8 z: 12 Scalene triangle5
x: 6 y: 8 z: 12 Scalene triangle6
x: 6 y: 8 z: 12 Scalene triangle7
std;
1x: 6 y: 8 z: 12 Scalene triangle9
x: 6 y: 8 z: 12 Scalene triangle72
number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 43252154721
std;
5x: 6 y: 8 z: 12 Scalene triangle6
number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 43252154724
x: 6 y: 8 z: 12 Scalene triangle7
std;
9checkTriangle[
1 using
9 void
checkTriangle[
4
x: 6 y: 8 z: 12 Scalene triangle6
number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 43252154724
x: 6 y: 8 z: 12 Scalene triangle9
x: 6 y: 8 z: 12 Scalene triangle72
#include
5std;
5#include
7
x: 6 y: 8 z: 12 Scalene triangle6
int
checkTriangle[
8checkTriangle[
9int
0int
1____92x: 6 y: 8 z: 12 Scalene triangle5
x: 6 y: 8 z: 12 Scalene triangle6
int
using
3x: 6 y: 8 z: 12 Scalene triangle6
using
5#include
7
#include
7
int
9 x: 6
y: 8
z: 12
Scalene triangle
00
number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 432521547202
x: 6 y: 8 z: 12 Scalene triangle6
x: 6 y: 8 z: 12 Scalene triangle7
x: 6 y: 8 z: 12 Scalene triangle03
x: 6 y: 8 z: 12 Scalene triangle044____104
x: 6 y: 8 z: 12 Scalene triangle5
Is
x: 6 y: 8 z: 12 Scalene triangle9
number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 432521547210
number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 43252154721
std;
5x: 6 y: 8 z: 12 Scalene triangle9
x: 6 y: 8 z: 12 Scalene triangle11
x: 6 y: 8 z: 12 Scalene triangle1229____29
x: 6 y: 8 z: 12 Scalene triangle14
x: 6 y: 8 z: 12 Scalene triangle9
number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 432521547210
number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 43252154729
std;
5x: 6 y: 8 z: 12 Scalene triangle03
x: 6 y: 8 z: 12 Scalene triangle04
checkTriangle[
9x: 6 y: 8 z: 12 Scalene triangle9
number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 432521547210
#include
5std;
5#include
7
x: 6 y: 8 z: 12 Scalene triangle6
number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 432521547229
x: 6 y: 8 z: 12 Scalene triangle6
using
5number = 1 print[id[number]] # 4325215472 print[id[1]] # 4325215472 number = 3 print[id[number]] # 4325215536 print[id[1]] # 432521547232
x: 6
y: 8
z: 12
Scalene triangle
06x: 6
y: 8
z: 12
Scalene triangle
04 int
1 O[1]
Auxiliary Space: O[1]