文本移动到下一行python 3.4

时间:2016-07-02 17:40:14

标签: python python-3.4

这是我第一次尝试用Python编写代码。我不明白为什么文本会转到下一行。我希望它是:

是否要删除" event"?
 Y或N

但它打印为:

您要删除"事件
&#34 ;?  Y或N

由于

# picks a random string from ideas34.txt
event = random.choice(open('ideas34.txt', 'r').readlines())

choice = int(input('\n' "What would you like to do?" '\n' "1  Random event" '\n' "2  Add a new event" '\n'
                   "3  Show all events" '\n' "4  Quit" '\n'))
# prints a random event from ideas34.txt
if choice == 1:
    print(event)
    d = input("Would you like to delete " "\"" + event + "\"? \n Y or N" '\n')
    # deletes the event picked
    if d == 'Y' or d == 'y':
        f = open('ideas34.txt', 'r')
        a = [event]
        lst = []
        for line in f:
            for word in a:
                if word in line:
                    line = line.replace(word, '')   # deletes event picked from ideas34.txt
            lst.append(line)
        f.close()
        f = open('ideas34.txt', 'w')
        for line in lst:
            f.write(line)
        f.close()

1 个答案:

答案 0 :(得分:0)

原因是混合单引号和双引号,然后将 newLine 和双引号全部放在同一行中

尝试使用

之类的东西
input('Would you like to delete ' '\"' + event + '\"?' '\n' Y or N' '\n')