I want to input two value in one line, use of two data type. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 2

I want to input two value in one line, use of two data type.

For ex. Subject= english and marks= 80 (english and 80 the value taken from user)

23rd May 2021, 2:26 PM
Sachin Pradhan
Sachin Pradhan - avatar
14 Answers
+ 4
Try this: subject, marks = input().split() print("Subject= ", subject, " and Marks= ",marks)
23rd May 2021, 3:20 PM
Isaac Fernandes
Isaac Fernandes - avatar
+ 4
Post your code here
23rd May 2021, 2:31 PM
Atul [Inactive]
+ 4
dear all, when assigning the splitted values from input, there is no need to put the variable names in squared brackets. subject, marks = input().split() # this is sufficient!
23rd May 2021, 3:59 PM
Lothar
Lothar - avatar
+ 3
23rd May 2021, 4:48 PM
Lothar
Lothar - avatar
+ 2
Can you be more clear?? Tell us the desired input and output atleast.
23rd May 2021, 2:51 PM
Isaac Fernandes
Isaac Fernandes - avatar
+ 2
You can input whatever you want using the the input function unless you specified it. So, if you want to take two different values from/byusing input function, you can do it like this, [Subject, marks ] = input().split() Then, submit the two values using whitespace.
23rd May 2021, 3:01 PM
Endalk
Endalk - avatar
+ 1
No its not working
23rd May 2021, 3:12 PM
Sachin Pradhan
Sachin Pradhan - avatar
+ 1
The above code only assigned the variables to something. You have to call/print or utilize them in some way. Like [Subject, marks ] = input().split() print('You have got {} in this {} subject'.format(marks, subject))
23rd May 2021, 3:16 PM
Endalk
Endalk - avatar
+ 1
Yes, it was work. Thanks you so much bro🤗👍
23rd May 2021, 3:27 PM
Sachin Pradhan
Sachin Pradhan - avatar
+ 1
Whatever i know, split() is use for space between two numbers. Am i right?
23rd May 2021, 5:22 PM
Sachin Pradhan
Sachin Pradhan - avatar
+ 1
Kiibo ghayal Your coding is correct but the value English and 80 would taken through the input() func. giving By user.
23rd May 2021, 5:33 PM
Sachin Pradhan
Sachin Pradhan - avatar
+ 1
Sachin Pradhan Not only for spaces but for strings
23rd May 2021, 6:28 PM
Atul [Inactive]
0
Any body can solve my problem?i don't know this solution but want this type of ans? print Subject=(input Math by user) as well print Marks=(input 75 by user) this output will come Subject= math and Marks= 75
23rd May 2021, 3:17 PM
Sachin Pradhan
Sachin Pradhan - avatar
0
Lothar Your code is wrong, its came👉 no output
23rd May 2021, 5:30 PM
Sachin Pradhan
Sachin Pradhan - avatar