Right Angle Hypotenuse Calculator

This is the place to post any code that you want to share with the community. Only completed scripts should be posted here.
Note: posts here are not necessarily endorsed by the community, and may represent amateur or even bad practices.

Right Angle Hypotenuse Calculator

Postby workhorse » Fri Jan 31, 2014 6:36 pm

I created this simple script to read a file containing two numbers, and calculate the hypotenuse of a right angle triangle.

Code: Select all
##open and read the file, then split both integers
f = open ('rosalind_ini2 (1).txt', "rt")
line =f.read()
values = line.split()

##store both integers and calculate hypotenuse.
x1 = int(values[0])
x2 = int(values[1])
hyp = x1**2 + x2**2
print hyp**1/2
Last edited by stranac on Fri Jan 31, 2014 7:52 pm, edited 1 time in total.
Reason: Moved from tutorial submissions. This really doesn't belong there.
workhorse
 
Posts: 5
Joined: Mon Jan 13, 2014 10:35 pm

Re: Right Angle Hypotenuse Calculator

Postby Mekire » Sat Feb 01, 2014 1:40 am

Not nearly enough people seem to know about math.hypot.
Code: Select all
>>> import math
>>> math.hypot(5,7)
8.602325267042627
>>>

-Mek
New Users, Read This
  • Use code tags when posting code.
  • Include any errors with your post (in code tags).
  • Describe your problem; not your chosen solution.
  • Make examples the minimum length to demonstrate your issue.
User avatar
Mekire
 
Posts: 1710
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

Re: Right Angle Hypotenuse Calculator

Postby workhorse » Sun Feb 02, 2014 5:22 pm

To be frank I am not at all well versed in python - for me I am going through this forum to learn and share what I've learned. Regardless, good code.
workhorse
 
Posts: 5
Joined: Mon Jan 13, 2014 10:35 pm


Return to Completed Scripts

Who is online

Users browsing this forum: No registered users and 3 guests