Python實(shí)現(xiàn)簡(jiǎn)單石頭剪刀布游戲
近日在學(xué)習(xí)Python的一些基礎(chǔ)知識(shí),覺(jué)得還是很有趣的一個(gè)一門(mén)語(yǔ)言!就目前的學(xué)習(xí)的一些知識(shí),編寫(xiě)了一些一個(gè)簡(jiǎn)單的石頭剪刀布的游戲。主要是熟悉一些Python的一些控制語(yǔ)句。
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é)果:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
python Tkinter的簡(jiǎn)單入門(mén)教程
這篇文章主要介紹了python Tkinter的簡(jiǎn)單入門(mén)教程,幫助大家更好的理解和學(xué)習(xí)使用python制作gui程序,感興趣的朋友可以了解下2021-04-04使Python代碼流暢無(wú)縫連接的鏈?zhǔn)秸{(diào)用技巧
鏈?zhǔn)秸{(diào)用是一種編程風(fēng)格,它允許將多個(gè)方法調(diào)用連接在一起,形成一個(gè)連貫的操作鏈,在Python中,鏈?zhǔn)秸{(diào)用常常用于使代碼更簡(jiǎn)潔、易讀,尤其在處理數(shù)據(jù)處理和函數(shù)式編程中應(yīng)用廣泛2024-01-01在Django的URLconf中使用多個(gè)視圖前綴的方法
這篇文章主要介紹了在Django的URLconf中使用多個(gè)視圖前綴的方法,Django是Python中最為著名的遵循MVC結(jié)構(gòu)的開(kāi)發(fā)框架,需要的朋友可以參考下2015-07-07使用Python實(shí)現(xiàn)廣告點(diǎn)擊率預(yù)測(cè)
廣告點(diǎn)擊率是指有多少用戶(hù)點(diǎn)擊了您的廣告與有多少用戶(hù)查看了您的廣告的比率,本文主要為大家介紹了如何使用Python實(shí)現(xiàn)廣告點(diǎn)擊率預(yù)測(cè),感興趣的小伙伴可以了解下2023-10-10對(duì)python3中的RE(正則表達(dá)式)-詳細(xì)總結(jié)
今天小編就為大家分享一篇對(duì)python3中的RE(正則表達(dá)式)-詳細(xì)總結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-07-07python?random庫(kù)的簡(jiǎn)單使用demo
這篇文章主要為大家介紹了python?random庫(kù)的簡(jiǎn)單使用demo,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03pyqt5+opencv?實(shí)現(xiàn)讀取視頻數(shù)據(jù)的方法
這篇文章主要介紹了pyqt5+opencv?實(shí)現(xiàn)讀取視頻數(shù)據(jù)的方法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-01-01