+ 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
5 Answers
+ 1
Go as:
numbers = input.split(" ")
If int(numbers[0]) > int(numbers[1]):
Print(numbers[0])
Else:
Print(numbers[1])
+ 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
+ 1
Maneren thanx
0
I will upload the code
0
Maneren
numbers = input().split(" ")
or
numbers = input().split()