[Solved] How to get input into a list via a function? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

[Solved] How to get input into a list via a function?

How can I get input from inp_cus_1 (lines 527 and 531) into the lis_cus list (line 86) using the app_cus() function (defined on line 122)? https://code.sololearn.com/cmfyA55BOLhm/?ref=app

18th Oct 2020, 3:25 PM
Adam Stork
Adam Stork - avatar
6 Answers
+ 2
I think you are trying this : def app_cus(age): lis_cus.append(age) inp_cus_1 = input() if inp_cus_1: app_cus(inp_cus_1)
18th Oct 2020, 3:42 PM
Jayakrishna 🇮🇳
+ 1
def app_cus(age): lis_cus.append(age) for i in range(3) : inp_cus_1 = input() if inp_cus_1: app_cus(inp_cus_1) #like this Adam Stork .but Iam not sure, you are looking like this or not. Above what I said is like this but it takes more lines : def app_cus(age1,age2,age3): lis_cus.append(age1) lis_cus.append(age2) lis_cus.append(age3) inp_cus_1 = input() inp_cus_2 = input() inp_cus_3 = input() app_cus(inp_cus_1, inp_cus_2,inp_cus_3) #add conditions, if you need to Check input is not empty or not like you did previously..
19th Oct 2020, 12:51 PM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 Thank you! Though I forgot to mention that there will also be inp_cus_2 and inp_cus_3. Is it possible to handle all three inputs via one function?
18th Oct 2020, 4:09 PM
Adam Stork
Adam Stork - avatar
0
Yes. Take 3 inputs. And pass 3 inputs as well collect 3 inputs in function defination..
18th Oct 2020, 10:22 PM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 I'm not sure how you mean, could you show me on a code, please?
19th Oct 2020, 6:07 AM
Adam Stork
Adam Stork - avatar
0
Jayakrishna🇮🇳 I will try, thank you!
19th Oct 2020, 12:52 PM
Adam Stork
Adam Stork - avatar