DHowell
DHowell

Reputation: 17

User input of a number to list of sequencial following numbers to 0

I'm pretty new to python/coding in general. I'm trying to take user input which I will get to later and turn it into a list from 0 - x. I have this :

x=[ ]
for i in range (args[0]+1):
    x = i
return x
print (main(5))

The x= i part is what I can't figure out right now. Each attempt I've done gives me IndexError: tuple index out of range

Upvotes: 0

Views: 29

Answers (2)

directive-41
directive-41

Reputation: 133

This works.

Replace target=10 with your user input.

Are you trying to code it in one line for brevity or for a particular requirement?

target = 10
x = [0]
while x[-1] < target:
    x.append(x[-1]+1)
print(x)

Upvotes: 0

Seraph Wedd
Seraph Wedd

Reputation: 864

Assuming you have saved your input to i, i.e.

i = input()

you can make a list by passing it through:

x = [num for num in range(int(i)+1)]

for example, if i=5, this will make:

x = [0, 1, 2, 3, 4, 5]

hope this helps.

Upvotes: 2

Related Questions