Python - 即使我得到了答案,我编程的错误系统也会显示错误

时间:2016-02-15 11:47:19

标签: python python-3.x

我的代码如下:

import re
import csv
import sys
import random

def RestartProgram():

    restart = input("Would you like to restart? Y/N")
    yes = "y" or "Y"

    if restart == yes:
        PhoneSupport()

def PhoneSupport():

    error = 0

    f = open("C:\PhoneSupp CSV.csv", "r")

    rows = re.split("\n", f.read())

    userInput = input("What has happened to your phone?")
    randInt = random.randint(0,9999)

    if userInput == "":
        print("You have not entered any problem.")
        RestartProgram()

    for index, row in enumerate(rows): #Loop that splits the rows into cells
        cells = row.split(',')
        if userInput in cells:
            error = 0
            print("A Solution has been found!:")
            print("")
            print(cells)
        elif userInput not in cells:
            error = 1


    if error == 1:
        print("No Solution has been found - Your support ticket is: " + str(randInt))
        print("")
        RestartProgram()
    elif error == 0:
        RestartProgram()

PhoneSupport()

1 个答案:

答案 0 :(得分:1)

在找到解决方案后,您没有打破for循环。 打印错误后添加break语句。这应该可以解决问题。