0

Can any one help me to get the following output in python

Enter x: 8 Enter y: 4 8 is greater than 4 The best I could do was x=input('Enter x: ') y=input('Enter y: ') if x<y: print ('x is less than y') else: print ('x is greater than y') Output Enter x: 8 Enter y: 4 x is greater than y

6th Dec 2018, 6:26 AM
Amogha Prakash
Amogha Prakash - avatar
3 Answers
+ 3
x=input('Enter x: ') y=input('Enter y: ') if x<y: print (x+' is less than '+y) else: print (x+' is greater than '+y)
6th Dec 2018, 6:45 AM
Rstar
Rstar - avatar
0
input() returns string, so you must convert to integer, compare it and then convert to string for correct print. x = int( input('Enter x: ')) y = int( input('Enter y: ')) if x < y: print (str(x) +' is less than ' +str(y)) else: print (str(x) +' is greater than ' +str(y)) ''' # or you can print it as separated values of different types if x < y: print (x, 'is less than', y) else: print (x, 'is greater than', y) ''' (for Rstar too) Note: If you compare string direct '5' > '2' is True, but '20' > '5' is False, because char '2' is before char '5' in chars table.
6th Dec 2018, 8:47 AM
zemiak
- 1
guess = int(input('Enter an integer : ')) guess1 = int(input('Enter an integer : ')) if guess == guess1: print('Congratulations, you guessed it.') elif guess < guess1: print('No, guess1 is a little higher than that') else: print('No, it is a little lower than that') print('Done')
6th Dec 2018, 6:36 AM
MsJ
MsJ - avatar