Apr-28-2017, 01:51 AM
Help! I'm a total newbie when it comes to programming, I need my program to calculate the distance between two points. I got the first part of my assignment done, I created a function with the distance formula. Here is the second part, please... help :'(. I've been looking on the web for hours.
Create another function named main that will be responsible for prompting the user for input and calling the distance function. Use exception handling to convert the user input to float. The user input should then be passed as arguments to distance with a function call. Store the return value from the distance function into a variable and then print the results in a pleasing format.
Create another function named main that will be responsible for prompting the user for input and calling the distance function. Use exception handling to convert the user input to float. The user input should then be passed as arguments to distance with a function call. Store the return value from the distance function into a variable and then print the results in a pleasing format.
import math def distance(x1,y1,x2,y2): dist = ((x1 - x2)**2 + (y1-y2)**2)**.5 return dist def main(dist): try: x1 = float(input("Enter a Number: ")) x2 = float(input("Enter a Second Number: ")) y1 = float(input("Enter a third number: ")) y2 = float(input("Enter a forth number: ")) else: print(distance)