Python實(shí)現(xiàn)簡(jiǎn)單石頭剪刀布游戲
近日在學(xué)習(xí)Python的一些基礎(chǔ)知識(shí),覺得還是很有趣的一個(gè)一門語言!就目前的學(xué)習(xí)的一些知識(shí),編寫了一些一個(gè)簡(jiǎn)單的石頭剪刀布的游戲。主要是熟悉一些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é)果:


以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Python+pyaudio實(shí)現(xiàn)音頻控制示例詳解
PyAudio?是語音處理的?Python?庫,提供了比較豐富的功能。本文將利用pyaudio控制指定設(shè)備,實(shí)現(xiàn)錄制音頻、采集音頻流、播放音頻,感興趣的可以了解一下2022-07-07
淺談Python中range與Numpy中arange的比較
這篇文章主要介紹了淺談Python中range與Numpy中arange的比較,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-03-03
Python通過跳板機(jī)訪問數(shù)據(jù)庫的方法
跳板機(jī)是一類可作為跳板批量操作的遠(yuǎn)程設(shè)備的網(wǎng)絡(luò)設(shè)備,是系統(tǒng)管理員和運(yùn)維人員常用的操作平臺(tái)之一。本文給大家介紹Python通過跳板機(jī)訪問數(shù)據(jù)庫的方法,感興趣的朋友跟隨小編一起看看吧2021-10-10
關(guān)于Python中的if __name__ == __main__詳情
在學(xué)習(xí)Python的過程中發(fā)現(xiàn)即使把if __name__ == ‘__main__’ 去掉,程序還是照樣運(yùn)行。很多小伙伴只知道是這么用的,也沒有深究具體的作用。這篇文字就來介紹一下Python中的if __name__ == ‘__main__’的作用,需要的朋友參考下文2021-09-09
Python使用flask-caching緩存數(shù)據(jù)的示例代碼
Flask-Caching 是 Flask 的一個(gè)擴(kuò)展,為任何 Flask 應(yīng)用程序添加了對(duì)各種后端的緩存支持,它基于 cachelib 運(yùn)行,并通過統(tǒng)一的 API 支持 werkzeug 的所有原始緩存后端,本文給大家介紹了Python使用flask-caching緩存數(shù)據(jù),需要的朋友可以參考下2024-12-12
利用Python和C語言分別實(shí)現(xiàn)哈夫曼編碼
這篇文章主要為大家詳細(xì)介紹了如何利用Python和C語言分別實(shí)現(xiàn)哈夫曼編碼,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2022-07-07

