简体   繁体   中英

Python Print statements don't work

a = input('enter a ') 
b = input('enter b ') 
c = input('enter c ')


def is_right_angled(a, b, c):
    a, b, c = sorted([a, b, c])             #sort inputs smallest to largest
    pathag=(a * a + b * b - c * c) #< 0.1   #a ^2 + b ^2 - c ^2 should = 0 approx

    if pathag<0.1:                          # test "pathag" to to see if  close
     print ("This is a right triangle")
    else:                                   # if "pathag" not close, not "right"
     print ("This is NOT a right triangle")

    return abs(a * a + b * b - c * c) < 0.1

There could be a couple issues specific to the print function not working (I think you might also want to revisit some of the logical assumptions driving your is_right_angled function.)

1) An input function creates a string variable. You will need to explicitly convert this to an int or float variable in order for your function to correctly work with these variables.

a = float(input('enter a '))

2) You are not actually calling the function in the above code. Be sure to call it or the code won't run. Add this to the end of your script:

is_right_angled(a, b, c)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM