在While循环中出现break语句的问题

时间:2013-11-06 05:16:39

标签: while-loop break python-3.3

我正在尝试编写一个程序,从用户收集信息,然后输出到文本文件。程序正确地收集输入,因为我插入的print语句告诉我,但是当输入指定的值时,break语句不会中断循环,并且输出文件永远不会更新。你能给出的任何建议都会有所帮助。谢谢!

# 1. Define Greeting:
def greeting():
    print("Welcome, user! Please enter the address data, or type 'quit'.")

# 2. Input
def inputData():
    name = input("Enter the name: ")
    address = input("Enter the address: ")
    city = input("Enter the city: ")
    state = input("Enter the state: ")
    zipCode = input("Enter the zip: ")
    phone = input("Enter the phone number: ")
    addressData = str(name + ", " + address + ", " +
                       city + ", " + state + ", "+ zipCode +
                       ", " + phone)
    print(addressData)
    return(name)

# 3. Write data to text file
def dataWrite():
    f.write(addressData + "\n")

# 4. Display the goodbye message:
def goodbye():
    print("Have a nice day!")

# 5. Define Main function:
def main():    
    greeting()
    while name != "quit":
         inputData()
         if name == "quit":
             break
         else:
             dataWrite()
    f.close()        
    goodbye()
main()

1 个答案:

答案 0 :(得分:0)

def main():    
    greeting()
    while name != "quit":
         name = inputData()
         if name == "quit":
             break
         else:
             dataWrite()
    f.close()        
    goodbye()

您没有获得inputData()的返回值。