+ 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
6 Respuestas
+ 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
+ 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)
+ 3
visph Yeah, but I do agree the way they put their point across is a bit misleading.
+ 2
visph I think you may be misunderstanding their objective, though yes, your code is functional.
+ 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())]
+ 1
👑 Prometheus 🇸🇬
Thanks, that worked fine , Jesus Christ blessed you 👍