我坐了整整一个星期,我不知道如何摆脱这些global points
。在
这里我定义points
。在
def init():
global points, hidden_password, hidden_password2, country, used, start_time
points = 0
hidden_password = []
hidden_password2 = []
country = ""
used = []
start_time = datetime.now()
welcome()
choice()
然后从choice到choice()
,到play_game()
,再到{points
达到5。在
然后它转到checking()
,从检查到letter()
,然后到checking_password()
,如果用户没有猜到正确的字母,它会将1加到points
并返回它。在
def checking_password(number):
global points, hidden_password2, hidden_password
if hidden_password2 == hidden_password:
points += number
time.sleep(1)
print("\n Boo! You have +", number, "penalty points!")
time.sleep(1)
hidden_password2 = hidden_password
if points < 4:
manage_graphics(points)
elif points == 4:
manage_graphics(points)
print(" Hint: It's a capital of " + country + ".")
elif points >= 5:
manage_graphics(5)
return points
如果有人想要,这里有一个完整的代码:https://codeshare.io/aYBAzb
可以使用类来存储属性。在
相关问题 更多 >
编程相关推荐