2016-11-24 95 views
-2

我尝试添加根据用户的回答一个变量提供如添加到一个变量在python

points = 0 
print("Do you have a cat or a dog?") 
response = input() 
if response == 'Dog' points=+1 
elif response == 'Cat' points=+2 

“点”是变量,它是0,现在这样依赖于答案用户给我如何添加一个数字变量,以便它可以从0更改为1或2

+0

使用字典动物名称与关联点数。 –

回答

-1
points = 0 
print("Do you have a cat or a dog?") 
response = input() 
if response == 'Dog': points=+1 
elif response == 'Cat': points=+2 

print points 

试试这个代码,你的if语句没有

+0

该问题询问如何将_添加到变量中;此解决方案不使用添加。 –

+0

@BryanOakley给我举个例子 – Anthony

1
points = 0 
print("Do you have a cat or a dog?") 
response = input() 
if response == 'Dog' :points+=1 
elif response == 'Cat':points+=2 

我认为你必须把+ =而不是= +。

或者,也许,这是simplier

points=points+1 
0
points = 0 
print("Do you have a cat or a dog?") 
response = input() 
if response == 'Dog' points=+1 
elif response == 'Cat' points=+2 

计算机认为这是

points = 0 
print("Do you have a cat or a dog?") 
response = input() 
if response == 'Dog' 0=+1 
elif response == 'Cat' 0=+2 

因为点= 0,所以当你 “添加” 到它, 点= + 1 你正在增加一个到没有和不影响分值。 这样做的更好的方式是 点=点+ 1 和电脑认为,随着 0 = 0 + 1 或 点+ = 1 ,使其更容易