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

13th Oct 2016, 8:20 AM
James T Togara
6 Respuestas
+ 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
13th Oct 2016, 5:44 PM
Sunera
+ 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)))
13th Oct 2016, 12:45 PM
Zen
+ 1
I tink every1 got it
8th Jan 2017, 5:22 AM
Sammy Elijah
+ 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)))
3rd Aug 2019, 5:12 AM
GYANENDRA PAL SINGH
0
if x > y: return 1 elif x == y: return 0 return -1
13th Oct 2016, 10:36 AM
Joshua Milamber
0
I TINK eveyone got it #DANUM @Sammy Elijah
8th Feb 2019, 11:48 AM
Braydon Wray
En tendencia hoy
PRO vs MAX