我在做一个猜谜游戏,我不能让分数说什么,除了0
我在谷歌上搜索了一下,发现一个公式不起作用,所以我来了
为了防止代码看起来很奇怪,这里有一个链接: http://www.codeskulptor.org/#user46_Rn6mbqc2fxzXniV.py
import random
totalScore = 0
lp = input ('Lets play the guessing game! \nPress Enter to start')
if (lp== ""):
print ("Score\n_____")
x1 = int(input("No.1 Type a number between 0 and 5"))
if (x1 !=(random.randint(0,5))):
input("Incorrect :/\n Press Enter to move on")
print ("+0")
score = totalScore + 0
else:
input("Correct!\n Press Enter to move on")
print ("+1")
x2 = int(input("No.2 Type a number between 0 and 10"))
if (x2 !=(random.randint(0,10))):
input("Incorrect :/\n Press Enter to move on")
print ("+0")
score = totalScore + 0
else:
input ("Correct!\n Press Enter to move on")
print ("+1")
score = totalScore + 1
x3 = int(input("No.1 Type a number between 0 and 15"))
if (x3 !=(random.randint(0,15))):
input("Incorrect :/\n Press Enter to move on")
print ("+0")
score = totalScore + 0
else:
input ("Correct!\n Press Enter to move on")
print ("+1")
score = totalScore + 1
x4 = int(input("No.1 Type a number between 0 and 20"))
if (x4 !=(random.randint(0,20))):
input("Incorrect :/\n Press Enter to move on")
print ("+0")
score = totalScore + 0
else:
input ("Correct!\n Press Enter to move on")
print ("+1")
score = totalScore + 1
x5 = int(input("No.1 Type a number between 0 and 25"))
if (x5 !=(random.randint(0,25))):
input("Incorrect :/\n Press Enter to move on")
print ("+0")
score = totalScore + 0
else:
input ("Correct!\n Press Enter to move on")
print ("+1")
score = totalScore + 1
totalScore = score
print ("Total Score:")
print (totalScore)
我正在努力让比赛增加所有的积分,并在最后展示他们
每次将
score
设置为0时,都会覆盖上一个score
。你想要做的不是score = totalScore + 1
(或0),而是totalScore += 1
(与totalScore = totalScore + 1
相同)输出示例:
在上面的示例中,我还删除了多余的
score = totalScore + 0
,因为将0添加到整数中没有任何作用感谢codeskulptor链接使使用代码变得超级简单
相关问题 更多 >
编程相关推荐