您的位置 首页 > 数码极客

如何将多个游戏用一个代码实现

经过了一段时间的学习,想必有的人已经开始动摇了,因为慢慢的出现了枯燥,乏味的状态,还有的一部分人出现了模糊不清楚,不想继续的念头,为了激励大人还有勾引起孩子继续学习下去的动力,我们今天发布几个游戏小脚本,可以重新勾引起孩子学习的念头,快来试试!

下面的脚本都是围绕着循环来写的,可以帮助你加深对循环的印象。

打开百度App,看更多图片

game.py

相信大家都玩过或者知道摇色子的游戏,就是说色盅里面有三个色子,我们来摇动色子,猜大小的游戏。说白了就是赌场里面的一个小游戏。

先上代码

#!/usr/bin/python2

import random

import sys

import time

result = []

while True:

re(in(1,7)))

re(in(1,7)))

re(in(1,7)))

print result

count = 0

index = 2

pointStr = ""

while index >= 0:

currPoint = result[index]

count += currPoint

index -= 1

pointStr += " "

pointStr += str(currPoint)

if count <= 10:

(pointStr + " -> " + "small" + "\n")

( 1 )

else:

(pointStr + " -> " + "big" + "\n")

( 1 )

result = []

输出结果如下:脚本用的是个无限循环模式,会一直自动摇色子,自动判断大小。

xatedhtst{xxxxx}157> game.py

[2, 5, 4]

4 5 2 -> big

[2, 5, 4]

4 5 2 -> big

[4, 3, 1]

1 3 4 -> small

[3, 5, 2]

2 5 3 -> small

[3, 5, 2]

2 5 3 -> small

gue

这个是一个心里测试游戏,可以帮你猜出对方心里想的是什么数字,快和好朋友或者孩子一起玩玩,他会觉得你很厉害,很神奇!

二话不说先上代码:

#!/usr/bin/python2

# -*- coding: UTF-8 -*-

import random

s = in(1,100))

#print(s)

m = int(input('please input the int :'))

while m != s:

if m > s:

print ('big')

m = int(input('please input the int:'))

if m < s:

print ('small')

m = int(input('please input the int:'))

if m == s:

print ('OK')

break;

运行结果: 系统会自动提是你你猜的数字比他默认的是大还是小,快来玩玩看看谁用的次数最少就能猜中!

xatedhtst{xxxxx}163> gue

please input the int :50

big

please input the int:25

big

please input the int:12

big

please input the int:6

big

please input the int:3

small

please input the int:4

OK

责任编辑: 鲁达

1.内容基于多重复合算法人工智能语言模型创作,旨在以深度学习研究为目的传播信息知识,内容观点与本网站无关,反馈举报请
2.仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证;
3.本站属于非营利性站点无毒无广告,请读者放心使用!

“如何将多个游戏用一个代码实现”边界阅读