Python實(shí)現(xiàn)簡單石頭剪刀布游戲
更新時間:2021年01月20日 15:02:29 作者:AiYong_SJTU
這篇文章主要為大家詳細(xì)介紹了Python實(shí)現(xiàn)簡單的石頭剪刀布的游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
近日在學(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)文章
使Python代碼流暢無縫連接的鏈?zhǔn)秸{(diào)用技巧
鏈?zhǔn)秸{(diào)用是一種編程風(fēng)格,它允許將多個方法調(diào)用連接在一起,形成一個連貫的操作鏈,在Python中,鏈?zhǔn)秸{(diào)用常常用于使代碼更簡潔、易讀,尤其在處理數(shù)據(jù)處理和函數(shù)式編程中應(yīng)用廣泛2024-01-01使用Python實(shí)現(xiàn)廣告點(diǎn)擊率預(yù)測
廣告點(diǎn)擊率是指有多少用戶點(diǎn)擊了您的廣告與有多少用戶查看了您的廣告的比率,本文主要為大家介紹了如何使用Python實(shí)現(xiàn)廣告點(diǎn)擊率預(yù)測,感興趣的小伙伴可以了解下2023-10-10對python3中的RE(正則表達(dá)式)-詳細(xì)總結(jié)
今天小編就為大家分享一篇對python3中的RE(正則表達(dá)式)-詳細(xì)總結(jié),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-07-07pyqt5+opencv?實(shí)現(xiàn)讀取視頻數(shù)據(jù)的方法
這篇文章主要介紹了pyqt5+opencv?實(shí)現(xiàn)讀取視頻數(shù)據(jù)的方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-01-01