import random,logging
logging.basicConfig(filename='E:\\python-project\\auto_project_10\\10.8.txt',level=logging.DEBUG,format='%(asctime)s-%(levelname)s:%(message)s')
#filename 写入文件的绝对路径,level代表级别有DEBUG,WARNING,INFO等
#format代表格式 asctime操作时间 levelname信息级别 message个人附加信息
logging.debug('start new 10.8.py project')
def main():
logging.debug('start of main project')
guss_coin()
def guss_coin():
guss=7
logging.debug('start guss_coin coin is %s'%(guss))
while guss!='':
guss=random.randint(0,1)
logging.debug('start guss_coin coin is %s' %(guss))
print('请猜一下正反(正:1,反:0)')
your_choose=input()
your_choose=int(your_choose)
if your_choose==1 or your_choose==0:
logging.debug('your_choose is wrong,choose is %s' %(your_choose))
#向路径下插入的内容为your_choose is wrong,choose is <your_choose>这个变量值
if your_choose==guss:
print('猜对了')
logging.debug('your_choose is %s' % (your_choose))
continue
else:
print('猜错了')
continue
print('请输入0或1\n')
continue
logging.debug('猜对一次')
elif your_choose==8:
logging.debug('跳出程序\n')
guss=''
continue
else:
logging.debug('your choose is %s'%(your_choose)+'real choose is %s'%(guss))
print('请输入0或1')
logging.debug('输入错误')
continue
if __name__=='__main__':
main()
logging模块的使用编写硬币游戏
最新推荐文章于 2024-08-18 14:08:21 发布