") 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