亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

python代碼實現猜拳小游戲

瀏覽:66日期:2022-07-03 17:10:48

本文實例為大家分享了python代碼實現猜拳小游戲的具體代碼,供大家參考,具體內容如下

游戲實現具體功能

原有的用戶登錄的信息均能保存在txt文件里,注冊的信息也能保存在txt里面格式如下:

python代碼實現猜拳小游戲

便于之后轉換成列表字典形式添加注冊數據

用戶的猜拳記錄也能保存在txt中并以如下格式顯示

格式如下:

python代碼實現猜拳小游戲

具體Python代碼:

#-*- coding=utf8 -*-# @author:sololi# date: 2020/10/24# 文件說明 :# 123文件存放 用戶信息 456 文件存放猜拳結果import sysfff= open(’123’,'r+',encoding='utf8')shuju=[]a=[]b=[]c=[]aa={}username=0for line in fff.readlines(): line=line.strip(’n’) a= line.split(’ ’) i=0 while i<len(a): b=a[i].split(’,’) i+=1 j=0 while j<len(b): if b==' ': break c=b[j].split(’:’,1) aa[c[0]]=c[1] i+=1 j+=1 shuju.append(aa.copy()) #將數據 轉換成列表字典形式便于后面登錄與注冊存放數據(copy是為了防止添加是數據類型不同出錯)fff.close()print('#######################')print('歡迎進入猜拳游戲')print('#######################')denglu=input('登錄輸入1,注冊輸入2') #登錄程序if denglu=='1' : while True: username = input('請輸入用戶名') jg1= 0 i = 0 while(i<len(shuju)): if (username == shuju[i]['用戶名']): print('用戶名正確') jg1=1 break i+=1 if(jg1!=1): print('用戶名錯誤') elif (jg1 == 1): break while True: password = input('請輸入密碼') jg2=0 i = 0 while(i<len(shuju)): if (password == shuju[i]['密碼']): print('密碼正確') jg2=1 break i+=1 if(jg2!=1): print('密碼錯誤') elif(jg2==1): breakelif denglu=='2' : while True: username = input('請輸入注冊的用戶名') jg3 = 0 i = 0 while (i < len(shuju)): if (username == shuju[i]['用戶名']): print('用戶名已經存在') jg3 = 1 break i += 1 if(jg3 == 0): password = input('請輸入注冊的密碼') print('注冊成功') print('登錄成功') fff = open('123', mode=’a+’, encoding='utf8') fff.seek(2) fff.write('用戶名:{},密碼:{}n'.format(username, password)) fff.close() breakelse: print('輸入有誤,結束登錄') sys.exit(0)while True: #猜拳游戲程序 xuanzhe = (input('進行游戲1n顯示信息2n退出游戲3')) if xuanzhe=='1': z=0.0 c=0.0 import random while True: guess=random.randint(1,3) num=int(input('選擇石頭(1)/剪刀(2)/布(3)')) if (num==1 and guess==2) or (num==2 and guess==3) or (num==3 and guess==1): print('勝') c=c+1 elif num ==guess: print('平') elif(num==1 and guess==3) or (num==2 and guess==1) or (num==3 and guess==2): print('負') else: print('輸入有誤') continue jieguo=input('是否繼續游戲,輸入任意退出游戲') z = z + 1 if jieguo=='是': continue else: break kd=((c/z)) print(’總數{:.0f}’ ’勝率:{:.2%}’.format(z,kd)) f=open('456',mode=’a+’,encoding='utf8') f.write('用戶名:{},總數:{:.0f},勝率:{:.2%}n'.format(username,z, kd)) f.close() elif xuanzhe=='2': f = open('456','r+',encoding='utf8') res = f.read() print(res) f.close() elif xuanzhe=='3': break else: print('輸入有誤請重新輸入')print('歡迎再次使用猜拳游戲')

初學者作品,有錯大神請指正

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 婷婷六月久久综合丁香可观看 | 日韩经典在线 | 亚洲国产精品嫩草影院久久 | 伊人网久久网 | 麻豆视传媒短视频网站-欢迎您 | 久久精品国产免费观看99 | 91porn丫九色| 免费观看a毛片一区二区不卡 | 欧美日韩亚洲国产精品一区二区 | 最新欧美精品一区二区三区不卡 | 国产精品果冻传媒在线 | 看全色黄大色黄女片爽老外 | 亚洲精品国产一区二区三 | 五月天六月婷婷 | 久草狼人 | 麻豆传媒免费视频 | 久久99亚洲综合精品首页 | 丁香综合激情 | 亚洲欧美一区二区三区在线观看 | 日韩中文字幕视频 | 国产白拍 | 奇米成人网| 中文字幕播放 | 亚洲国产成人久久午夜 | 亚洲国产精品综合久久2007 | 国产欧美亚洲精品综合在线 | 国内日本精品视频在线观看 | 黄黄视频在线观看 | 亚洲三级国产 | 欧美日韩精品一区二区三区视频 | 在线精品视频在线观看高清 | 亚洲欲色 | 大杳蕉精品视频在线观看 | 亚洲协和影视 | 日本96在线精品视频免费观看 | 72种姿势欧美久久久久大黄蕉 | 国产精品黄网站 | 国产精品国产三级国产a | 小明成人免费永久性看看 | 日本高清在线一区二区三区 | 年轻人www影视|