For instance, in C we can do something like this:
// Reads two values in one line scanf("%d %d", &x, &y)
One solution is to use raw_input() two times.
x, y = input(), input()
Another solution is to use split()
x, y = input().split()
Note that we don’t have to explicitly specify split(‘ ‘) because split() uses any whitespace characters as a delimiter as default.
One thing to note in the above Python code is, both x and y would be of string. We can convert them to int using another line
x, y = [int(x), int(y)] # We can also use list comprehension x, y = [int(x) for x in [x, y]]
Below is complete one line code to read two integer variables from standard input using split and list comprehension
# Reads two numbers from input and typecasts them to int using # list comprehension x, y = [int(x) for x in input().split()]
Australia
UK
UAE
Singapore
Canada
New
Zealand
Malaysia
USA
India
South
Africa
Ireland
Saudi
Arab
Qatar
Kuwait
Hongkong
Copyright 2016-2023 www.programmingshark.com - All Rights Reserved.
Disclaimer : Any type of help and guidance service given by us is just for reference purpose. We never ask any of our clients to submit our solution guide as it is, anywhere.