Python實現(xiàn)簡單石頭剪刀布游戲
更新時間:2021年01月20日 15:02:29 作者:AiYong_SJTU
這篇文章主要為大家詳細介紹了Python實現(xiàn)簡單的石頭剪刀布的游戲,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
近日在學(xué)習(xí)Python的一些基礎(chǔ)知識,覺得還是很有趣的一個一門語言!就目前的學(xué)習(xí)的一些知識,編寫了一些一個簡單的石頭剪刀布的游戲。主要是熟悉一些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')
下面是結(jié)果:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
pyqt5+opencv?實現(xiàn)讀取視頻數(shù)據(jù)的方法
這篇文章主要介紹了pyqt5+opencv?實現(xiàn)讀取視頻數(shù)據(jù)的方法,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-01-01