+ 1
SOLVED (Inputs in code coach)
Hi, can I ask how can I get many inputs fro m code coach into my code? I dont know exact number of inputs coming so i cannot write just i1=input(), i2=input(), i3... thx
10 Respuestas
+ 3
First make a list of input. Get list as input and take int or str as you want from your list
+ 2
"I don't know exact number of inputs"
~OP
In code coach when they tell you to accept multiple inputs they generally give them on same line. so accept all inputs using single call to input() and then split them.
Just to give you an idea I'll show sum of all numbers given as input.:
```
nums = input().split()
#accept as string and split , returns list
nums = [int(x) for x in nums]
#converting all elements to int, you can keep string depending upon requirement.
print(sum(nums))
#print sum of all.
```
I don't think I have understood your question completely 🤔, It's just an assumption. You can edit your question and add more details about problem.
+ 2
Thanks for helping me. Your code worked, and what i have to say is that i was so disappointed with results because in results_inputs were like three numbers even thought (as you said) the problem states that first number should be number of inputs which will come. That was "five" and i saw only three numbers in result_inputs and then I was like wtf, what am I supposed to do if the exercise is badly written :D Okey anyway, thanks for bringing some light into my brain :)
+ 1
Thanks for replies,
I think in exercise named That's odd... they dont give all inputs on the same line. I did try this : a = input().split()
print(a)
As output I got just first number from input - ["5"]
+ 1
as I said it, if the exercise said that as input you have a number or a single value, just use a = input() but if it's said that the input is a list or a sentence or something like that, you might use input().split().
+ 1
Bernard Pivko , Kindly read the problem (That's odd) again.
It clearly states that first input will be integer that tells number of inputs to be taken.
n = int(input())
#get number of inputs
nums =[ ]
for i in range(n):
let num = int(input())
nums.append(num)
This is how you can take input for given problem. Try to solve rest of the problem on your own. This will help you get better understanding of what you have learned 💪
+ 1
Another way is: 5
4
6
7
This is example.
+ 1
I think very few people knowing this way see my reply ^^^^^^^^^^^^^^
0
you don't have to take care of that, just take the number of input you need. and don't print something which is not asked! mostly it is just one input and one output, so you may have one input() statement and print what you're ask to print.
- 1
list=[]
while True:
inp=input("insert to list: ")
if inp=="print":
print(list)
elif inp=="exit":
break
else:
list.append(inp)
continue