Python实现石头-剪刀-布小游戏
生活随笔
收集整理的這篇文章主要介紹了
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...')breakelif 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实现石头-剪刀-布小游戏的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 安卓qq文件下载到哪个文件夹(安卓qq文
- 下一篇: Python:递归输出斐波那契数列