我做了一个游戏的工作版本,玩家对电脑。我不知道如何确定一个获胜者,经过大约30分钟的研究,我决定问这里
这是一个简单的游戏。计算机是随机的,所以你的对手没有策略。我试着让电脑读前一行,看看谁做了最后一步(对手赢了),我试着用减法。我已经两个月没写代码了,有什么遗漏吗
import random
print("That pen game you used to play as a kid (it's kinda like 21
dares)")
newnum = random.randint(20,30)
print("Starting number: {}".format(newnum))
while newnum > 0:
pRemove = int(input("How many do you want to remove: "))
if pRemove >= 1 and pRemove <= 3:
newnum = newnum - pRemove
print("{} left".format(newnum))
if newnum <= 0:
break
elif pRemove > 3 or pRemove < 1:
print("Put a number from 1-3")
break
else:
print("error")
exit()
CPUremove = random.randint(1, 3)
newnum = newnum - CPUremove
print("CPU removed {}. {} left!".format(CPUremove, newnum))
最后我要看“你赢了!”或者“你输了!”紧接着节目就结束了(我的意思是在它的末尾添加一些东西,而不是更改代码)
在
while
循环之前,设置一个变量:在播放器取出一些笔后的检查中,将变量设置为一个新值:
然后,在循环之后,你可以检查谁最后去了
相关问题 更多 >
编程相关推荐