我该怎么重复这个词

2024-06-16 12:26:58 发布

您现在位置:Python中文网/ 问答频道 /正文

while True:
import csv  #Creates a CSV file
name = input("Hello what is your name?")
print("Hello",name,"!")
opinion = input ("How do you feel about the Icentre A. Good B. Amazing C. I don't like it      Please type your answer here -->")
if opinion == 'Good'or opinion == 'good' or opinion == 'A' or opinion == 'a':
    print("Thanks!")
    improvements = input("Anything we can improve?")
    print("Thanks for your feedback!")
    reason = ""
elif opinion == 'Amazing' or opinion == 'amazing'or opinion == 'B' or opinion == 'b':
    print("Thats awesome!")
    improvements = input("Anything we can improve?")
    print("Thanks for your feedback!")
    reason = ""
elif opinion == 'I dont like it' or opinion == 'i dont like it'or opinion == 'C' or opinion == 'c':
    reason = input("Please tell us why -->")
    print("Thank you for your feedback.")
    improvements = ""
results = [ 
       [name,  opinion, improvements, reason]
       ]
                         #w = write,  a = append 
myfile = open("OpenEveningResults.csv", "a", newline="")

mywriter = csv.writer(myfile)
mywriter.writerows(results)
myfile.close()

if name == "stop":
    break

这是说“打破'外环”。这是一个错误,但我看不出我在代码中哪里出错了。不知道我是否缩进错误或分开和代码,不应该分开


Tags: orcsvnameforinputyouritmyfile
2条回答

需要对while循环体使用缩进,如下所示:

while True:
    import csv  #Creates a CSV file
    name = input("Hello what is your name?")
    print("Hello",name,"!")
    opinion = input ("How do you feel about the Icentre A. Good B. Amazing C. I don't like it      Please type your answer here  >")
    if opinion == 'Good'or opinion == 'good' or opinion == 'A' or opinion == 'a':
        print("Thanks!")
        improvements = input("Anything we can improve?")
        print("Thanks for your feedback!")
        reason = ""
    elif opinion == 'Amazing' or opinion == 'amazing'or opinion == 'B' or opinion == 'b':
        print("Thats awesome!")
        improvements = input("Anything we can improve?")
        print("Thanks for your feedback!")
        reason = ""
    elif opinion == 'I dont like it' or opinion == 'i dont like it'or opinion == 'C' or opinion == 'c':
        reason = input("Please tell us why  >")
        print("Thank you for your feedback.")
        improvements = ""
    results = [ 
           [name,  opinion, improvements, reason]
           ]
                             #w = write,  a = append 
    myfile = open("OpenEveningResults.csv", "a", newline="")

    mywriter = csv.writer(myfile)
    mywriter.writerows(results)
    myfile.close()

    if name == "stop":
        break

while True:

剩下的代码放在这里,缩进

相关问题 更多 >