【发布时间】:2021-09-11 10:28:50
【问题描述】:
我在函数之外定义了“timesUsrPlayed”变量,因此它不会重置它。当我将 1 添加到变量时,我在函数“randomPartOfGame”中调用 var 'timesUsrPlayed' 的时间下得到黄色摆动线。当我将鼠标悬停在显示“timesUsrPlayed”未定义 Pylance(reportUndefinedVariable)”的行上时。我真的希望我说得清楚:
import os
import random
# a funcion to clear the console
clear = lambda: os.system('cls')
# counts the plays
timesUsrPlayed = 0
def randomPartOfGame():
n = random.randint(0,6)
p = random.randint(0,6)
print(str(n) + " and " + str(p))
if n != p:
print("im sorry try again")
randomPartOfGame()
timesUsrPlayed += 1
elif n == p:
print("yay you did, it took you "+ str(timesUsrPlayed) +" times to get a double")
def mainGameFunction():
print('game starting...')
time.sleep(2)
clear()
print('welcome you need to get a double in dice (is means get the same number)')
randomPartOfGame()
【问题讨论】:
标签: python