0
l want to program code that compare two values x and y , return 1 if x is greater than y else return 0 if x is equal to y or else return -1 if x less than y . Then program must accept user input
6 Answers
+ 2
#function
#will return -1 or 0 or 1
def chk(x,y):
z = x - y
return (z > 0) - (z < 0)
#User Inputs
a = int( input("x = ") )
b = int( input("y = ") )
#call function
print( chk(a,b) )
OR IF YOU ALREADY HAVE INPUTTED X AND Y ;
((x-y) > 0 ) - ((x-y) < 0 )
WILL GIVE -1,0,1 AS YOU HAVE ASKED
+ 1
def cmp(x, y):
if x > y:
return 1
elif x == y:
return 0
return -1
x = int(input("Enter x"))
y = int(input("Enter y"))
print(str(cmp(x, y)))
+ 1
I tink every1 got it
+ 1
def cmp(x, y):
if x > y:
return 1
elif x == y:
return 0
return -1
x = int(input("Enter x"))
y = int(input("Enter y"))
print(str(cmp(x, y)))
0
if x > y:
return 1
elif x == y:
return 0
return -1
0
I TINK eveyone got it
#DANUM
@Sammy Elijah