-2

What's the problem in this code? It looks correct. but outputs are not correct. by the way, (none of them is greater than or equal to the sum of the other two) It's triangular rule...

import sys

def areTriangular(x,y,z):
    if x<y+z and y<x+z and z<x+y:
        return True
    else:
        return False

a = sys.argv[1]
b = sys.argv[2]
c = sys.argv[3]


m = areTriangular(a,b,c)

print(m)
bkk
  • 81
  • 1
  • 7
  • What input do you use? What output do you get? What output do you expect? – khelwood Apr 16 '18 at 11:25
  • for example, I put 3 4 5 numbers, and output is. False. but it would be True – bkk Apr 16 '18 at 11:25
  • 2
    You need to convert your input (strings) to numbers (floats or ints). – khelwood Apr 16 '18 at 11:25
  • oooo. khlelwood. thank you so much it workes. but I am wondering why it couldn't before? because that function not understand that values are numbers? – bkk Apr 16 '18 at 11:28
  • If you use `<` on strings then they are compared alphabetically, so the result is different. – khelwood Apr 16 '18 at 11:29
  • thanks for that information. I didn't know it compared alhabetically. It's very good information. thanks again :) – bkk Apr 16 '18 at 11:31

1 Answers1

-2

Is because Python is 0 indexed so you need to use:

a = sys.argv[0]
b = sys.argv[1]
c = sys.argv[2]

instead of:

a = sys.argv[1]
b = sys.argv[2]
c = sys.argv[3]
tudor opran
  • 27
  • 1
  • 7