我與蟒蛇進行實驗,我做了這個小的數學遊戲。儘管我在評分系統方面存在一些問題。每當玩家得到的答案是正確的,我想得分1.我試圖遞增,但我還沒有得到它每一個球員得到一些正確的時間增加。 赫雷什代碼Python的數量遞增
import operator
import random
operations = {
"addition": ("+", operator.add),
"substraction": ("-", operator.sub),
"multiplication": ("*", operator.mul),
"division": ("/", operator.floordiv),
}
def ask_operation(difficulty, maxtries=3):
maxvalue = 5 * difficulty
x = random.randint(1, maxvalue)
y = random.randint(1, maxvalue)
op_name, (op_symbol, op_fun) = random.choice(list(operations.items()))
result = op_fun(x, y)
score = 0
print("Difficulty level %d" % difficulty)
print("Now lets do a %s calculation and see how clever you are." % op_name)
print("So what is %d %s %d?" % (x, op_symbol, y))
for ntry in range(1, 1+maxtries):
answer = int(input(">"))
if answer == result:
print("Correct!")
score += 1
print score
return True
elif ntry == maxtries:
print("That's %s incorrect answers. The end." % maxtries)
else:
print("That's not right. Try again.")
return False
def play(difficulty):
while ask_operation(difficulty):
difficulty += 1
print("Difficulty level achieved: %d" % difficulty)
play(1)
在整個帖子中,您的縮進是否正確? –
沒有它沒有。我複製並從文本編輯粘貼,所以我失去了格式化。我會編輯 – user2379090
耶修復縮進請。目前,看起來你將每個新問題的分數設置爲0:/ – Dunno