I am trying to create an empty list and for some reason it is telling me it's invalid syntax? it also flags the next line with the same error, saying that while count<amount: is invalid. am i wrong for thinking this doesnt make sense? using vsc. thanks in advance. my code looks like this.
list=[]
count=0
while count < amount :
s=int(input"enter a number:")
list.append(s)
count= count 1
i tried to use list={}, list=() even though i know those are wrong. it also flags lines like list4=[1,3] ??
CodePudding user response:
amount
is not defined. Define it with a number like 5 and try then.
You also need to make sure the variable list
is called something else, it is a python-reserved word.
Lastly, make sure the input
function has parenthesis ()
around it. e.x. input("enter number: ")
CodePudding user response:
In python the indent is 4 spaces.
You need to change the variable name "list" because it is a built in name in python.
You need to put brackets after input.
amount = 5
numberList = []
count = 0
while count < amount:
s = int(input("enter a number:"))
list.append(s)
count = 1
CodePudding user response:
I think the problem there is that you're using input() wrong, it should be:
int(input("Enter a number: "))
Also, I am assuming that you defined amount earlier in your code, otherwise you will need to in order for your code to work :D
I also saw a comment saying that list is a python reserved function: It is, however you can use it as a variable name and it will not return an error :)
Have a good day :D