+ 39
How to take two inputs in python
when we click run then how to assign two values in it
10 Respostas
+ 20
a = input()
b = input()
print(a,b)
Now when you run it...
Give different input in different lines like -
5
4
#Work done... It'll print :
5 4
+ 30
thank you Nikhil
+ 3
# taking two inputs at a time
x, y = input("Enter two values: ").split()
print("Number of boys: ", x)
print("Number of girls: ", y)
print()
+ 2
thanks Nikhil
+ 1
this may also depend on the goals. if you need, for example, a user to enter more than 2 numbers (5, 10 or 100), it's easier for you to work with the lists.
you can ask to enter the numbers (exact number of times (5, 10 or 100) = range(5)) and send these numbers to the list:
lst = []
for x in range(5):
x = int(input())
lst.append(x)
#lst = [6, 3, .., .., ..]
0
input1 = input("Enter the first input: ")
input2 = input("Enter another input: ")
0
Print(a,b)
0
Code example:
#We give a 3 and b 4
a = input("Enter Something")
b = input("Enter Something")
print(a, b)
# a = 3, b = 4 As I mentioned
Output:
34
- 1
a, b =[int(x) for x in input("Enter two numbers: ").split()].
It's very sophisticated
Simpler solution.
From my last program:
from numpy import *
import numpy as np
import math as m
from itertools import *
arrentry=input("Type the numbers wich will form the array: \n")
print (arrentry)
def conversion(arrentry):
arrentry =arrentry.split()
limit=len(arrentry)
a=np.zeros(limit)
dim=int(m.sqrt(limit))
for x in count(0):
if x<=limit-1:
a[x]=arrentry[x]
else:
break
b=a.reshape((dim, dim))
return b
def checking(b):
dim=b.shape[0]
sw= True
for x in range(dim):
y=dim-x-1
while x<=y:
if b[x][y]!=b[y][x]:
sw= False
break
else:
y-=1
return sw
print(conversion(arrentry))
print("The array which is over this line, is it owl matrix: ")
print(checking(conversion(arrentry)))
As you can see, I take the input as it was a string,and then I convert it in a list, an unidimensional array or multidimensional array.
I hope you understand me, because my English isn't very good.
- 2
yv