Python实现简单石头剪刀布游戏
更新时间:2021年01月20日 15:02:29 作者:AiYong_SJTU
这篇文章主要为大家详细介绍了Python实现简单的石头剪刀布的游戏,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
近日在学习Python的一些基础知识,觉得还是很有趣的一个一门语言!就目前的学习的一些知识,编写了一些一个简单的石头剪刀布的游戏。主要是熟悉一些Python的一些控制语句。
import random
while 1:
s=int(random.randint(1,3))
print(s)
print()
if s==1:
ind="stone"
elif s==2:
ind="scissors"
elif s==3:
ind="paper"
m=input('Please input your option,if you input the end, this game will be end. ')
blist=['stone','scissors','paper']
if (m not in blist) and (m!='end'):
print('your input is wrong and please input the right option again or end the game: ')
elif (m not in blist) and (m=='end'):
print('the game is ending now...')
break
elif m==ind:
print('draw')
elif (m=='stone' and ind=='scissors') or (m=='paper' and ind=='stone') or (m=='scissors' and ind=='paper'):
print('you win this game')
elif (m=='stone' and ind=='paper') or (m=='paper' and ind=='scissors') or (m=='scissors' and ind=='stone'):
print( 'you loss this game')
下面是结果:


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
浅谈Python中range与Numpy中arange的比较
这篇文章主要介绍了浅谈Python中range与Numpy中arange的比较,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2020-03-03
关于Python中的if __name__ == __main__详情
在学习Python的过程中发现即使把if __name__ == ‘__main__’ 去掉,程序还是照样运行。很多小伙伴只知道是这么用的,也没有深究具体的作用。这篇文字就来介绍一下Python中的if __name__ == ‘__main__’的作用,需要的朋友参考下文2021-09-09
Python使用flask-caching缓存数据的示例代码
Flask-Caching 是 Flask 的一个扩展,为任何 Flask 应用程序添加了对各种后端的缓存支持,它基于 cachelib 运行,并通过统一的 API 支持 werkzeug 的所有原始缓存后端,本文给大家介绍了Python使用flask-caching缓存数据,需要的朋友可以参考下2024-12-12


最新评论