Alternative multy input | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Alternative multy input

User input n integers How i can get a list of input with short code? Long code us: A=int(input()) B=int(inout()) ..... W124=int(input())

29th Jan 2024, 9:25 PM
Коко Ша
Коко Ша - avatar
4 Answers
+ 6
Коко Ша , what have done so far to find a proper way for this task? can you post your try here: > put your code in playground, save it there, create a link from the code and post this link here.
29th Jan 2024, 9:29 PM
Lothar
Lothar - avatar
+ 3
If it meets your needs you could take all the inputs from the user at once, separated by spaces or commas for example and use .split() to populate list 'L'. For example: l = input().split() print(l) Would do as you need if the numbers were '1 2 3 4 5 6 7 8'. However, these produce a list of strings and not integers. If you combine it with list comprehension and write: l = [int(x) for x in input().split()] print(l) you will generate a list of integers.
29th Jan 2024, 10:56 PM
StuartH
StuartH - avatar
+ 1
Lothar ,StuartH I knew other variant b=list(int(input()) for _ in range(N)) Its works! But i am happy for your help 😊
29th Jan 2024, 11:04 PM
Коко Ша
Коко Ша - avatar