create account

Solving one side of right-angled triangle using Pythagorean Theorem in Python by kimp0gi

View this thread on: hive.blogpeakd.comecency.com
· @kimp0gi · (edited)
$0.13
Solving one side of right-angled triangle using Pythagorean Theorem in Python
<center>![the-pythagorean-formula.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1516018374/bymisl5pbx98zgf1waq6.png)
[image source](https://i0.wp.com/www.mathbootcamps.com/wp-content/uploads/the-pythagorean-formula.png?resize=560%2C315)</center>
<center>*In a right-angled triangle:
the square of the hypotenuse is equal to
the sum of the squares of the other two sides.*</center>
#### What Will I Learn?
This tutorial aims to:

- Solve one side of a right-angled triangle using Pythagorean Theorem in Python


#### Requirements

- Python IDLE

#### Difficulty

- Basic

#### Tutorial Contents
##### The Code:
First, we import sqrt function from math module into the current namespace.
<code>from math import sqrt</code>

Display an information about the program (may not be included).
<code>print('This is a Pythagorean Theorem calculator! Calculate one side of right-angled triangle.')
print('Assume the sides are a, b, c and c is the hypotenuse.')</code>

Second, ask the user on which side to calculate and assign it to a variable (i used variable 'choice').
<code>choice = input('Which side (a, b, c) do you want to calculate? side: ')</code>

Third, making if ... elseif condition statement.
If the user wants to find for the hypotenuse which is side c.
<code>if choice == 'c':
    a = float(input('Input the length of side a: '))
    b = float(input('Input the length of side b: '))</code>
Solving for the c with the formula: √a^2+b^2
<code>c = sqrt(a * a + b * b)</code>
Display the value of side c
<code>print('The length of side c is %g: ' %(c))</code>

Else if, the user wants to find for the  side b.
<code>elif choice == 'b':
    a = float(input('Input the length of side a: '))
    c = float(input('Input the length of side c: '))</code>
Solving for the b with the formula: √c^2-a^2
<code>b = sqrt(c * c - a * a)</code>
Display the value of side b
<code>print('The length of side b is %g: ' %(b))</code>

Else if, the user wants to find for the  side a.
<code>elif choice == 'a':
     b = float(input('Input the length of side b: '))
    c = float(input('Input the length of side c: '))</code>
Solving for the a with the formula: √c^2-b^2
<code>a = sqrt((c * c) - (b * b))</code>
Display the value of side a
<code>print('The length of side a is %g: ' %(a))</code>

Lastly, if the input is invalid.
<code>else:
    print('Invalid Input!')</code>


#### Curriculum
Please visit my previous tutorials:

- [Solving Quadratic Equation in easiest way using Python](https://steemit.com/utopian-io/@kimp0gi/solving-quadratic-equation-in-easiest-way-using-python)

<center>Thanks for reading! Hope you learn something.</center>
---

    

<br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@kimp0gi/solving-one-side-of-right-angled-triangle-using-pythagorean-theorem-in-python">Utopian.io -  Rewarding Open Source Contributors</a></em><hr/>
👍  , , , , , , , ,
properties (23)
authorkimp0gi
permlinksolving-one-side-of-right-angled-triangle-using-pythagorean-theorem-in-python
categoryutopian-io
json_metadata{"community":"utopian","app":"utopian/1.0.0","format":"markdown","repository":{"id":102230800,"name":"Pythagoras_theorem","full_name":"khushalimehta/Pythagoras_theorem","html_url":"https://github.com/khushalimehta/Pythagoras_theorem","fork":false,"owner":{"login":"khushalimehta"}},"pullRequests":[],"platform":"github","type":"tutorials","tags":["utopian-io","steemit-engineering","programming","cebu","philippines"],"users":["kimp0gi"],"links":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1516018374/bymisl5pbx98zgf1waq6.png","https://i0.wp.com/www.mathbootcamps.com/wp-content/uploads/the-pythagorean-formula.png?resize=560%2C315","https://steemit.com/utopian-io/@kimp0gi/solving-quadratic-equation-in-easiest-way-using-python"],"image":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1516018374/bymisl5pbx98zgf1waq6.png"],"moderator":{"account":"scipio","time":"2018-01-16T13:36:54.847Z","flagged":true,"reviewed":false,"pending":false}}
created2018-01-15 13:48:12
last_update2018-01-16 13:36:54
depth0
children3
last_payout2018-01-22 13:48:12
cashout_time1969-12-31 23:59:59
total_payout_value0.106 HBD
curator_payout_value0.019 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,868
author_reputation3,215,145,789,728
root_title"Solving one side of right-angled triangle using Pythagorean Theorem in Python"
beneficiaries
0.
accountutopian.pay
weight2,500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id29,706,973
net_rshares17,381,824,828
author_curate_reward""
vote details (9)
@scipio ·
$1.86
Your contribution cannot be approved because it is not as informative as other contributions. See the [Utopian Rules](https://utopian.io/rules). Contributions need to be informative and descriptive in order to help readers and developers understand them.

Explanation:
- the [GitHub repo](https://github.com/khushalimehta/Pythagoras_theorem/blob/master/Pythagoram%20Theorem.py) you linked to, is 9 months old, probably is written by somebody else, and does the exact same thing as you are trying to teach. (Only your code is less elegant). I won't call it "plagiarism" but it's not original either!
- your tutorial doesn't provide the full Python3 script,
- if you want to contribute more Python3 tutorials - you're welcome!- but at least then try to explain in a step-by-step fashion how the Python 3 language works, or explain how to implement / use a certain module (included in the standard lib, or external), but **do not** publish tutorials for very trivial examples: now you picked the Pythagorean Theorem (c^2 = a^2 + b^2), and I don't think any serious Python developer is interested in a tutorial to solve that Theorem,
- but any beginner Pythonista **is interested** in good tutorials explaining **language and/or module concepts**.

Good luck on your next Python3 tutorial!

You can contact us on [Discord](https://discord.gg/uTyJkNm).
**[[utopian-moderator]](https://utopian.io/moderators)**
👍  
properties (23)
authorscipio
permlinkre-kimp0gi-solving-one-side-of-right-angled-triangle-using-pythagorean-theorem-in-python-20180116t134334838z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-01-16 13:43:36
last_update2018-01-16 13:43:36
depth1
children2
last_payout2018-01-23 13:43:36
cashout_time1969-12-31 23:59:59
total_payout_value1.396 HBD
curator_payout_value0.460 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,404
author_reputation34,229,822,336,032
root_title"Solving one side of right-angled triangle using Pythagorean Theorem in Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id29,943,086
net_rshares197,385,340,209
author_curate_reward""
vote details (1)
@kimp0gi ·
thank you sir
properties (22)
authorkimp0gi
permlinkre-scipio-re-kimp0gi-solving-one-side-of-right-angled-triangle-using-pythagorean-theorem-in-python-20180116t134939228z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-01-16 13:49:36
last_update2018-01-16 13:49:36
depth2
children0
last_payout2018-01-23 13:49:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length13
author_reputation3,215,145,789,728
root_title"Solving one side of right-angled triangle using Pythagorean Theorem in Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id29,944,310
net_rshares0
@utopian.tip ·
Hey @scipio, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!
properties (22)
authorutopian.tip
permlinkre-re-kimp0gi-solving-one-side-of-right-angled-triangle-using-pythagorean-theorem-in-python-20180116t134334838z-20180116t155524
categoryutopian-io
json_metadata""
created2018-01-16 15:55:24
last_update2018-01-16 15:55:24
depth2
children0
last_payout2018-01-23 15:55:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length156
author_reputation238,310,597,885
root_title"Solving one side of right-angled triangle using Pythagorean Theorem in Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id29,970,721
net_rshares0