logging模块的使用编写硬币游戏

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()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值