我的代码如下:
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()
答案 0 :(得分:1)
在找到解决方案后,您没有打破for
循环。
打印错误后添加break
语句。这应该可以解决问题。