I need to repeat the process of inputting the numbers as many as mentioned in the variable number
:
number = int(input("How many numbers do you want in your list? "))
list = [for i in range(0,number)]
If you want to have a bunch inputted at once, separated by commas, you could use:
w = input("Enter stuff to add to the list, separated by commas.")
my_list = w.split(",")
print(my_list)
This code accepts input as comma-separated stuff like this: a, 1, @^
and turns it into this: ['a', '1', '@^']
The code works by accepting comma-ed input as w
, then splitting it into a list by the commas, using the built in split()
method.
You may simply do:
Here,
my_list
will hold thelist
ofn
numbers entered by the user.Note:
list
is built-in type in Python. Do not use it as variable name