怎么导入日志

来源:3-2 项目作业

慕标348660

2019-11-02 17:53:48

import random# 判断输入成功后的语句描述def succ_text():    reall_num = random.randint(int(start_one), int(end_one))    print("真值:{}".format(reall_num))    count = 1    while True:        text = int(input("请继续输入你猜测的值:"))        # 未在指定区间的测试        if int(end_one) < text or text < int(start_one):            print("对不起您输入的数字未在指定区间!")            count += 1            continue        elif text > reall_num:            print("Higher than the answer")            count += 1            continue        elif text < reall_num:            print("Lower than the answer")            count += 1            continue        elif text == reall_num:            print("恭喜您!用了{}次赢得了游戏!".format(count))            break        print("***********")num_list = []# 构建界面效果print("**********欢迎进入数字竞猜小游戏**********")start_one = input("数字区间的起始值")num_list.append(start_one)end_one = input("数字区间的终止值")num_list.append(end_one)print("所产生的数字区间为:{}".format(num_list))# 判断程序输入是否正确list1 = [start_one, end_one]lst = list(filter(lambda str1: str1.isdigit(), list1))while True:    # 判断成功的语句    if len(lst) == 2 and start_one != end_one and start_one < end_one:        succ_text()        break    # 输入失败的提醒语句    elif len(lst) != 2:        print("您所输入的为非数字字符,请重新录入!")        break    elif len(lst) == 2 and start_one == end_one:        print("您所输入的数字区间相同,请重新录入!")        break    elif len(lst) == 2 and start_one != end_one and start_one > end_one:        print("您所输入的数字区间有误,请重新录入!")        break


日志文件
import datetime
import text_one.text01


def write_record(count, text):
    now = str(datetime.datetime.now())
    with open('record.txt', 'a+', encoding='utf-8') as f:
        f.write('{0}:第{1}次您测试的数字为:{2}\n'.format(now, count, text ))


if __name__ == '__main__':
    write_record()

写回答

1回答

时间,

2019-11-03

同学,你好。同学是将write_recore()函数放在了text_one文件夹的text01文件中吗?

在程序中使用时,导入模块后,直接调用就可以了

例:

from text_one import text01

test01.write_record(text)

如果我的回答解决了您的疑惑,请采纳!祝学习愉快~~~~

0

0 学习 · 8160 问题

查看课程