用python编一个扔骰子猜大小的游戏,要求三局两胜制

") dice = random.randrange(1, 7) if guess == "small": winning() if dice = 4 else losing() else: game(w, l) if __name__ == '__main__': game(0, 0)from random import cho...
用python编一个扔骰子猜大小的游戏,要求三局两胜制
搜集的资料:
import random def game(w, l): def winning(): print("You are right.") again(w+1, l) def losing(): print("You are wrong.") again(w, l+1) def again(w, l): ans = input("Play again?(y/n)") if ans == 'n': print("You played %s rounds, and you won %s rounds" % (w+l, w)) elif ans == 'y': game(w, l) else: again(w, l) guess = input("Please input your guess(big/small): ") dice = random.randrange(1, 7) if guess == "small": winning() if dice <= 3 else losing() elif guess == "big": winning() if dice >= 4 else losing() else: game(w, l) if __name__ == '__main__': game(0, 0)2014-04-13
from random import choicefrom time import sleepgo_on='y'won=0played=0while go_on=='y': right=0 for i in range(3): inputed='' while inputed!=='big' and inputed!=='small': inputed=raw_input('Please input your guess(big/small):') if inputed==choice['big','small']: print 'You are right' right+=1 else: print 'You are wrong' played+=1 if right>1: won+=1 go_on='' while go_on!='y' and go_on!='n': go_on=raw_input('Play again?')print 'You played',played,'rounds, and you won',won,'rounds.'sleep(2)2020-03-15
参考我之前回答的问题:http://zhidao.baidu.com/question/982003419122883339.html?oldq=1
要求好像一样。2014-04-12
mengvlog 阅读 57 次 更新于 2025-12-16 10:52:45 我来答关注问题0
檬味博客在线解答立即免费咨询

编程相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部