0
How to put more than one input in python
For example I have to code to find average of two numbers given
1 Answer
+ 1
# Hi! Either you do all the inputs on the same line, and separate the numbers with a space:
mylist = input().split()
n1 = int(mylist[0])
n2 = int(mylist[1])
# You can make the code a bit more comapact, like this:
n1, n2 = (int(s) for s in input().split())
# Or you can put the inputs in different lines:
n1 = int(input())
n2 = int(input())
# You can make the code a bit more comapact, like this:
n1, n2 = (int(input()) for i in (0, 1))
# input() return a string, so if you need numbers, you have to convert it:
# âą int() is for converting to integer.
# âą float() is for floats (number with decimal point).