简单的记事本数据输入程序需要修复

时间:2015-11-02 20:29:01

标签: if-statement while-loop conditional python-3.4

您好,我最近有这个程序正常运行但现在它摆弄它现在它不起作用,因为当我在程序要求时在shell中运行它时,您是否想要输入用户" ;我打字#34;是"它没有要求用户输入他/她的名字,表格00/00/0000,运行时间,邮政编码的DOB。它只是打印"你想看到你的记录吗?"如果有人能帮忙的话,我会非常感谢p.s im真的很新,所以我现在不会100%理解一些事情。

def openfile1(name,dob,time,postcode):
file=open('runnerdata.txt', 'a')
file.write(name+":")
file.write(dob+":")
file.write(time+":")
file.write(postcode+ ":\n")
file.close()

while True: 
    enter=input("Do you want to enter a user? ")
    if enter=="no":
        file=open('runnerdata.txt', 'r')
        list=(file.readlines())
        enter2=input("Do you want to see your records? ")
        if enter2=="no":
                break
        elif enter2=="yes":
        name2=input("Enter name to see your records ")
        for line in list:
            if line.split(":")[0]==name2:
                print(line)

    elif enter=="yes":
        name=input("Enter name ")
        dob=input("Enter your DOB in form 00/00/0000 ")
        time=input("Enter your run time ")
        postcode=input("Enter your postcode ")
        openfile1(name,dob,time,postcode)

1 个答案:

答案 0 :(得分:0)

def openfile1(name,dob,time,postcode):
    file=open('runnerdata.txt', 'a')
    file.write(name+":")
    file.write(dob+":")
    file.write(time+":")
    file.write(postcode+ ":\n")
    file.close()

while True:
    enter=input("Do you want to enter a user? ")
    if enter=="no":
        file=open('runnerdata.txt', 'r')
        list=(file.readlines())
        enter2=input("Do you want to see your records? ")
        if enter2=="no":
                break
        elif enter2=="yes":
            name2=input("Enter name to see your records ")
        for line in list:
            if line.split(":")[0]==name2:
                print(line)

    elif enter=="yes":
        name=input("Enter name ")
        dob=input("Enter your DOB in form 00/00/0000 ")
        time=input("Enter your run time ")
        postcode=input("Enter your postcode ")
        openfile1(name,dob,time,postcode)

试试这个