You can only add variables together if both variables are either an integer or a string, but not a boolean (well, you kinda can but it’s not effective). For example:
>>> var = 1
>>> var2 = 4
>>> var + var2
5
>>> stringvar="Hello "
>>> stringvar2 = 'world.'
>>> stringvar + stringvar2
'Hello world.'
>>> boolean1 = True
>>> boolean2 = False
>>> boolean1 + boolean2
1
The reason that works is because:
>>> True == 1
True
>>> False == 0
True
EDIT:
It seems you have added in more code, so I’ll show you what you’re doing wrong.
The reason you’re getting a Syntax Error is because you have elif ValueError
. This doesn’t work. First, there isn’t even a ValueError, there can’t be as you have an input(). If you want to check whether a number is not 0 or 1, do this:
in1 = input("number 1 please")
if in1 == 1:
final += 1 # I've also changed this. final += 1 is the same as final = final + 1
elif in1 == 0:
final += 0
elif in1 != 1 or in1 != 0:
print("please enter a 1 or a 0")
I highly suggest reading over some python tutorials. This is some basic syntax.
4
solved how do you add the values of variables in python?