+ 1

Hi, does anyone know how I can put the information from an int(input) in a list?

I'm doing a test task and I need to take the information from an int(input) or an input and put it in a list. I being trying but I can't find a way to do it. one of the examples i made is this: items = [] n=int(input()) if n >=0: print items.append(n) But it tells me"incorrect sintax" If anyone can help me I'll appreciate

25th Feb 2021, 11:00 PM
Alan Restrepo
Alan Restrepo - avatar
6 Answers
+ 3
items = map(float,input().split()) # you just need to put spaces separated values on once line... # if you want just string, you doesn't need map # if you want int, just replace float by int
25th Feb 2021, 11:10 PM
visph
visph - avatar
+ 3
print items.append(n) This is Python 2 syntax. Furthermore, the append method returns nothing, even though it changes the list. What you have to do is first run the append method: items.append(n) Then print the list: print(items) Final code l: items = [] n = int(input()) if n>=0: items.append(n) print(items)
25th Feb 2021, 11:18 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 3
visph Yeah, but I do agree the way they put their point across is a bit misleading.
25th Feb 2021, 11:27 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
visph I think you may be misunderstanding their objective, though yes, your code is functional.
25th Feb 2021, 11:19 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
I have strictly answered to the question: hox put information from input in list... however, maybe anthony silver just want to do: n = [int(input())]
25th Feb 2021, 11:22 PM
visph
visph - avatar
+ 1
👑 Prometheus 🇸🇬 Thanks, that worked fine , Jesus Christ blessed you 👍
25th Feb 2021, 11:27 PM
Alan Restrepo
Alan Restrepo - avatar