I’ve been playing around with trying to make a range from an input.
But can’t get it to work despite others on the internet says it should work.
What am I doing wrong?
start = int(input("whats the end of the range? "))
range = []
for i in range(1, start):
print(f"first number is: {i}")
range.append(i)
print("numbers are now: ", range)
However terminal is giving me the
File “ex33.py”, line 38, in
for i in range(1, start):
TypeError: ‘list’ object is not callable
Hi @ktrager it will work. The only thing that you have to change is the name of the variable range = []. You call it like the Python built-in function range(). So Python will mistakenly call that function instead of your global variable.
Change range = [] to something else like v_range = [] and it will work.
start = int(input("whats the end of the range? "))
v_range = []
for i in range(1, start):
print(f"first number is: {i}")
v_range.append(i)
print("numbers are now: ", v_range)
But attention: you can only input a number!
$ python3.6 test.py
whats the end of the range? 3
first number is: 1
first number is: 2
numbers are now: [1, 2]
You can make a test:
Write the following in your code:
print(range)
And watch the output carefully. It will tell you that range is of type <class 'range'>
Hi @ktrager don’t worry. I don’t think it’s obvious to a beginner. I already spent longer periods of time, sometimes days, to locate an error similar to this.