我运行该功能时未配置我的分数标签或机会计数。有人可以帮忙吗?问题标签变化完美,但分数标签没有变化,我不明白为什么会这样。
def checkans(self):
chances = 0
score = 0
count = 0
while chances == 3:
break
else:
operations=['+', '-', '*']
a = random.randint(1,15)
b = random.randint(1,15)
random.shuffle(operations)
op = operations[0]
self.label.configure(text=(a,op,b))
if op == '+':
ans = a + b
if op == '-':
ans = a - b
if op == '*':
ans = a * b
self.e.focus_set()
if self.e.get() == ans:
score += 1
self.scorelabel.configure(text=('score', score))
else:
chances += 1
答案 0 :(得分:-1)
尝试一下:
def checkans(self): chances = 0 score = 0 count = 0 while chances < 3: operations=['+', '-', '*'] a = random.randint(1,15) b = random.randint(1,15) random.shuffle(operations) op = operations[0] self.label.configure(text=(a,op,b)) if op == '+': ans = a + b if op == '-': ans = a - b if op == '*': ans = a * b self.e.focus_set() if self.e.get() == ans: score += 1 self.scorelabel.configure(text=('score', score)) else: chances += 1
当将while
与else
一起使用时,其他将仅执行一次。