Larger number in two numbers in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Larger number in two numbers in python

Hello! Please help me with the below problem in python. I can write the code using two input statements. But the problem requires that the first line of code contains two numbers separated by spaces. Thanks Given two numbers as input, print the larger number. Input Format: The first line of input contains two numbers separated by a space Output Format: Print the larger number Example: Input: 2 3 Output: 3

13th Feb 2019, 7:27 PM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
5 Answers
+ 1
Go as: numbers = input.split(" ") If int(numbers[0]) > int(numbers[1]): Print(numbers[0]) Else: Print(numbers[1])
13th Feb 2019, 8:27 PM
Maneren
Maneren - avatar
+ 1
the input looks more like a string than a set of numbers. that would make me think convert at first but then the word Split() comes to mind. hey presto... split method by default splits on whitespace (space, tab, carriage return and newline) if you do not supply an argument to it. >>> " \r 42\n\r \t\n \r0\n\r\n".split() ... ohh look it chucks out numbers ['42', '0'] wiithout the fancy bits >>> "42 0".split() # or .split(" ") ['42', '0'] ohh still chucks out numbers lol the rest should be easy If one numbers greater than the other its the biggest else its not or its equal lol
13th Feb 2019, 8:29 PM
peter
peter - avatar
+ 1
Maneren thanx
14th Feb 2019, 5:38 AM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
0
I will upload the code
13th Feb 2019, 7:43 PM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
0
Maneren numbers = input().split(" ") or numbers = input().split()
14th Feb 2019, 4:32 AM
Diego
Diego - avatar