[英]I coded as follows, why it didn't compile as "my name is Maria, my age is 11." please? Thank you ;)
[英]Why doesn't my variable value get updated? thank you for your help, I havent coded in a while and I did not know about what you were saying so thanks
这是代码
import random
bank = 0
for i in range(100000):
gamble = int(input())
win = random.randint(1, 2)
if win == 1 :
print("lose")
bank - gamble
else:
print("win")
bank + gamble
print(bank)
有人可以帮我吗,我不是一个pythoneer,只是一个初学者级别的编码器,所以我想得到一些帮助和解释为什么它不起作用
您正在减去两个数字,但是,您对结果什么也不做 - 您期望什么? 就像在现实生活中一样,从另一个数字中减去一个数字并不会改变其中一个数字。 当您将两个数字相加、相除、相乘时,情况也是如此。 您要么必须通过将其分配给变量来保存数学运算的结果:
if win == 1 :
print("lose")
bank = bank - gamble
else:
print("win")
bank = bank + gamble
或通过在运算符后放置等号来进行数学运算:
if win == 1 :
print("lose")
bank -= gamble
else:
print("win")
bank += gamble
bank - gamble
bank + gamble
这两个表达式不存储创建赋值表达式所需的副作用。
尝试这个:
bank -= gamble
bank += gamble
或者:
bank = bank - gamble
bank = bank + gamble
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.