1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > python掷骰子猜大小_python摇骰子猜大小的小游戏

python掷骰子猜大小_python摇骰子猜大小的小游戏

时间:2024-03-21 09:13:12

相关推荐

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

原文:/pythonal/p/6008834.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。