import random
import time
import pickle
import sys
import os
def encode(s):
return ' '.join([bin(ord(c)).replace('0b', '') for c in s])
def decode(s):
return ''.join([chr(i) for i in [int(b, 2) for b in s.split(' ')]])
name=input('输入账户名,若没有输入注册:')
if name == '注册':
path=os.getcwd()
for i in range (0,1000):
namewj = str(i)
passwordwj =str(i)
nameyz=os.getcwd() + '/用户名'+namewj+'.txt'
passwordyz=os.getcwd() + '/密码'+passwordwj+'.txt'
if not os.path.exists(nameyz):
file = open(path+'/用户名'+namewj+'.txt','w')
file = open(path+'/密码'+passwordwj+'.txt','w')
file.close
break
namezc =input('用户名:')
passwordzc = input('密码:')
namezcjm=encode(namezc)
passwordzcjm=encode(passwordzc)
pickle.dump(namezcjm,open(path+'/用户名'+namewj+'.txt','wb'))
pickle.dump(passwordzcjm,open(path+'/密码'+passwordwj+'.txt','wb'))
else :
path=os.getcwd()
for i in range (0,1000):
namewj = str(i)
passwordwj =str(i)
nameyz=os.getcwd() + '/用户名'+namewj+'.txt'
passwordyz=os.getcwd() + '/密码'+passwordwj+'.txt'
if os.path.exists(nameyz):
namezcjm =pickle.load(open(path+'/用户名'+namewj+'.txt','rb'))
passwordzcjm =pickle.load(open(path+'/密码'+namewj+'.txt','rb'))
else:
print('无此用户,错误!')
sys.exit()
namezc=decode(namezcjm)
passwordzc=decode(passwordzcjm)
if name == namezc:
password =input('输入密码:')
if password == passwordzc:
print('登陆成功!')
break
else :
print('密码错误!')
sys.exit()
nd = int(input('是否开启限定回合制,按0取消输入任意数字及限定次数'))
sb=False
if nd !=0:
cmax=nd
a=int(input('1,100猜一个数对了有糖'))
c=1
Guessthenumbers=random.randint(1,100)
if a < Guessthenumbers or a > Guessthenumbers:
cmax -=1
cs=input('猜错了呢是否开启提升按1开启任意键关闭')
print('目前还剩下次数:',cmax,)
if cs =='1':
print('已经开启提升')
while cs =='1':
if a < Guessthenumbers:
print ('偏小')
if a > Guessthenumbers:
print ('偏大')
if a == Guessthenumbers:
break
cmax -=1
print('还剩下:',cmax,)
a=int(input('继续'))
c +=1
if cmax <=0:
print('恭喜你')
time.sleep(3)
print('次数耗尽')
sb =True
input()
break
else:
while a !=Guessthenumbers:
cmax -=1
print('还剩下:',cmax,)
a=int(input('错误,继续:'))
c +=1
if cmax <=0:
print('恭喜你')
time.sleep(3)
print('次数耗尽')
sb =True
input()
break
if sb ==True:
print('猜错了!下次再见')
if a ==Guessthenumbers:
print('恭喜你猜对了次数:',c,)
else:
a=int(input('1,100猜一个数对了有糖'))
c=1
Guessthenumbers=random.randint(1,100)
if a < Guessthenumbers or a > Guessthenumbers:
cs=input('猜错了呢是否开启提升按1开启任意键关闭')
if cs =='1':
print('已经开启提升')
while cs =='1':
if a < Guessthenumbers:
print ('偏小')
if a > Guessthenumbers:
print ('偏大')
if a == Guessthenumbers:
break
a=int(input('继续'))
c +=1
else:
while a !=Guessthenumbers:
a=int(input('错误,继续:'))
c +=1
print('恭喜你猜对了次数:',c,)
input()
|