Is there a way to input in the middle of a python statement? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Is there a way to input in the middle of a python statement?

For ex. a=int(input("enter number of items: ") Now I want to add "items" in it so the output goes something like this >>> enter a number of items: <input> items

25th Jul 2018, 4:16 PM
485949
10 Answers
+ 3
print(int(input("enter num of items:")), "items") a= int(input("enter num of items:")) print(a,'items')
25th Jul 2018, 4:48 PM
E_E Mopho
E_E Mopho - avatar
+ 2
That worked! Thanx Mr E_E Mopho
25th Jul 2018, 4:50 PM
485949
+ 2
Aaah, I misunderstood - I thought you wanted to take several inputs and print them out in one line!
25th Jul 2018, 5:01 PM
HonFu
HonFu - avatar
+ 1
It has to be in one line of code?
25th Jul 2018, 4:38 PM
HonFu
HonFu - avatar
+ 1
If you knew the number of inputs you want, you could go with this pattern: print ([input () for i in range (5)])
25th Jul 2018, 4:59 PM
HonFu
HonFu - avatar
+ 1
Nah! It's nothing to worry, actually. Your method is useful too. However, it was showing an EOFError, what's it?
25th Jul 2018, 5:05 PM
485949
+ 1
it means that you have to input all items on separate lines if you are running it on sololearn
25th Jul 2018, 5:33 PM
Markus Kaleton
Markus Kaleton - avatar
+ 1
Got it. Thanks Markus!
25th Jul 2018, 5:37 PM
485949
+ 1
a = int(input("how many items would you like on the list)) for i in range(a): itemlist = [] b = input("please enter item#{}".format(i)) itemlist.append(b) that should work as well if you want the list in a variable (didnt test)
25th Jul 2018, 5:39 PM
Markus Kaleton
Markus Kaleton - avatar
0
Yup! That's true.
25th Jul 2018, 4:41 PM
485949