首页 > 代码库 > python摇骰子猜大小的小游戏
python摇骰子猜大小的小游戏
#小游戏,摇筛子押大小的小游戏 import random #定义摇筛子的函数: def roll_dice(number = 3,points = None): print (‘<<<<< Roll The Dice >>>>>‘) if points is None: points = [] while number > 0: point = random.randrange(1,7) points.append(point) number = number - 1 return points #将点数转换为大小的函数: def roll_result(total): isBig = 11 <= total < 18 isSmall = 3 <= total < 10 if isBig: return ‘isBig‘ elif isSmall: return ‘isSmall‘ #开始游戏的函数; def start_game(): print (‘<<<<< GAME START >>>>>‘) choices = [‘isBig‘,‘isSmall‘] your_choices = input(‘isBig or isSmall:‘) if your_choices in choices: points = roll_dice() total = sum(points) youWin = your_choices == roll_result(total) if youWin: print(‘The points are‘, points, ‘You win !‘) else: print(‘The points are‘, points, ‘You lose !‘) else: print(‘Invalid Words‘) start_game()
python摇骰子猜大小的小游戏
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。