SOLVED (Inputs in code coach) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

26th Mar 2020, 5:23 PM
Bernard Pivko
Bernard Pivko - avatar
10 Answers
+ 3
First make a list of input. Get list as input and take int or str as you want from your list
28th Mar 2020, 5:44 AM
Wade
Wade - avatar
+ 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.
26th Mar 2020, 5:44 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 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 :)
26th Mar 2020, 7:02 PM
Bernard Pivko
Bernard Pivko - avatar
+ 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"]
26th Mar 2020, 6:12 PM
Bernard Pivko
Bernard Pivko - avatar
+ 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().
26th Mar 2020, 6:20 PM
John Robotane
John Robotane - avatar
+ 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 💪
26th Mar 2020, 6:30 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 1
Another way is: 5 4 6 7 This is example.
31st Mar 2020, 1:24 PM
Wade
Wade - avatar
+ 1
I think very few people knowing this way see my reply ^^^^^^^^^^^^^^
31st Mar 2020, 1:44 PM
Wade
Wade - avatar
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.
26th Mar 2020, 5:42 PM
John Robotane
John Robotane - avatar
- 1
list=[] while True: inp=input("insert to list: ") if inp=="print": print(list) elif inp=="exit": break else: list.append(inp) continue
28th Mar 2020, 3:41 PM
Lafaed
Lafaed - avatar