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
10 Answers
+ 3
print(int(input("enter num of items:")), "items")
a= int(input("enter num of items:"))
print(a,'items')
+ 2
That worked! Thanx Mr E_E Mopho
+ 2
Aaah, I misunderstood - I thought you wanted to take several inputs and print them out in one line!
+ 1
It has to be in one line of code?
+ 1
If you knew the number of inputs you want, you could go with this pattern:
print ([input () for i in range (5)])
+ 1
Nah! It's nothing to worry, actually. Your method is useful too.
However, it was showing an EOFError, what's it?
+ 1
it means that you have to input all items on separate lines if you are running it on sololearn
+ 1
Got it. Thanks Markus!
+ 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)
0
Yup! That's true.