How do you make a right triangle in python?

Last update on August 19 2022 21:51:44 [UTC/GMT +8 hours]

Python Basic - 1: Exercise-34 with Solution

Write a Python program to check whether three given lengths [integers] of three sides form a right triangle. Print "Yes" if the given sides form a right triangle otherwise print "No".

Input:
Integers separated by a single space.
1 ≤ length of the side ≤ 1,000

Pictorial Presentation:

Sample Solution:

Python Code:

print["Input three integers[sides of a triangle]"]
int_num = list[map[int,input[].split[]]]
x,y,z = sorted[int_num]
if x**2+y**2==z**2:
    print['Yes']
else:
    print['No']

Sample Output:

Input three integers[sides of a triangle]
 8 6 7
No

Flowchart:

Python Code Editor:

Have another way to solve this solution? Contribute your code [and comments] through Disqus.

Previous: Write a Python program to compute the digit number of sum of two given integers.
Next: Write a Python program which solve the specified equation.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

Python: Tips of the Day

Creating a sequence of numbers [zero to ten with skips]:

>>> range[0,10,2]
[0, 2, 4, 6, 8]  

  • Exercises: Weekly Top 16 Most Popular Topics
  • SQL Exercises, Practice, Solution - JOINS
  • SQL Exercises, Practice, Solution - SUBQUERIES
  • JavaScript basic - Exercises, Practice, Solution
  • Java Array: Exercises, Practice, Solution
  • C Programming Exercises, Practice, Solution : Conditional Statement
  • HR Database - SORT FILTER: Exercises, Practice, Solution
  • C Programming Exercises, Practice, Solution : String
  • Python Data Types: Dictionary - Exercises, Practice, Solution
  • Python Programming Puzzles - Exercises, Practice, Solution
  • C++ Array: Exercises, Practice, Solution
  • JavaScript conditional statements and loops - Exercises, Practice, Solution
  • C# Sharp Basic Algorithm: Exercises, Practice, Solution
  • Python Lambda - Exercises, Practice, Solution
  • Python Pandas DataFrame: Exercises, Practice, Solution
  • Conversion Tools
  • JavaScript: HTML Form Validation

Professor gave us a simple code that executes a square and we need to add/change the code to output the right triangle shape as shown below. It's just a simple loop within a loop code, but I can't find tips or help anywhere for creating shapes with Python without the code looking extremely confusing/difficult. I need a simple explanation what to do and why I need to make those changes.

[Nested loop code to create right triangle in Python]

The code given that executes a square:

Draw Square

size = input['Please enter the size: ']
chr  = raw_input['Please enter the drawing character: ']

row = 1
while row 

Chủ Đề