猜牌游戏,猜牌,吃饭聚会时要喝洒,大家都


吃饭聚会时要喝洒,大家都爱玩一个猜牌的游戏。游戏规则是:

(1)大家围着坐

(2)主持人(不参于猜牌的人),从两个1~9牌中抽取两张出来,做为被猜的数字。比如53

(3)右手边的玩家猜。

(4)如果猜中,就被罚喝酒。本轮游戏结束,下一轮此人相主持人。回到第2步。

(4)如果没有猜中,比如66,主持人则根据玩家报的数字,并报新的数据的范围(0~66)。回到第3步。

#!/usr/bin/env python#-*-coding:gb2312-*-#'''             **** Guess Number ****This is a guessing number game.At the beginning of each round, it will generate a numberrange from 1 to 99. Player should guess what number it is,then input. If the number player input is equal to what program generated, player win and end of this round. Else, program will narrow the range. Then player guess again. Repeat this untill player win.This game is suitable for several players. Each of playersguesses one by one. The player who gets the right number will be win.--------import randomdef one_round(down_limit=0, up_limit=100) :    '''One round. Input \\'q\\' to quit'''        the_number = random.randint(down_limit, up_limit)    while True :        range = '(' + str(down_limit) + '~' + str(up_limit) + ')'        user_input = raw_input('Please input number' + range + ': ')        if user_input == 'q' :            print 'User cancel.'            break        try :            user_input = int(user_input)        except :            print 'ERROR: Input invaild.'            continue        if down_limit < user_input < up_limit :            if user_input == the_number :                break            else :                if user_input > the_number :                    up_limit = user_input                else :                    down_limit = user_input                if up_limit - down_limit == 2 :                    print 'The number is the other'                    break        else :            print 'Out of range !'    print 'The number is %d' % (the_number)if __name__ == '__main__' :    print '=' * 50    print __doc__    print '-' * 50    while True :        one_round()        print '-' * 50        play_again = raw_input('Play again? ([y]/n) : ')        if play_again == 'n' or play_again == 'N' :            break    print 'Thank for you playing, Bye ~~'    print '=' * 50#该片段来自于http://byrx.net

评论关闭