尝试/除非程序块未运行
问题描述:
try块根本没有运行...有人可以找出原因吗?尝试/除非程序块未运行
case = open("phone.txt", "r+")
phone = ["What brand of phone do you have?", "What model?", "What version?", "How much memory?", "What seems to be the problem?"]
laptop = ["What brand of laptop do you have?", "What model?", "How much RAM?", "How much storage?", "What seems to be the problem?"]
tablet = ["What brand of tablet do you have?", "What model?", "What version?", "How much memory?", "What seems to be the probem?"]
specs = []
keyword = ["crack", "cracked", "wet", "water", "sound", "charge", "charger", "smashed", "slow", "boot", "startup", "blue", "responding", "", "", ""]
possibeSolutions = ["System: 'You should take your phone to get the screen replaced.'", "System: 'You should take your phone to get the screen replaced.'", "System: 'You should dry your device in rice.'", "", "", "", "", "", "", "", "", "", "", "", "", ""]
count = 0
device = input("System: 'What type of device do you have?'\nYou: ")
specs.append(device)
def problems(device, brand, model, version, memory, problem):
solution = False
specs = [brand, model, version, memory, problem]
problem2 = problem.split(" ")
for i in problem2:
for n in keyword:
if i.lower() == n.lower():
print(possibeSolutions[keyword.index(n)])
solution = True
if solution == False:
try:
case2 = case.readlines()
fileLen = len(case2)
caseNum = case2[fileLen - 2]
caseNum = int(caseNum) + 1
print("...")
except ValueError:
caseNum = 1
print("...")
finally:
print("...")
case.write(str(caseNum) + "\n(" + str(specs) + ")\n")
print("System: 'Your problem has been added the the database and one of our engineers will check it out later.'")
if "phone" in device.lower():
for i in phone:
print("System: '" + i + "'")
answer = input("You: ")
specs.append(answer)
elif "laptop" in device.lower():
for i in laptop:
print("System: '" + i + "'")
answer = input("You: ")
specs.append(answer)
elif "tablet" in device.lower():
for i in tablet:
print("System: '" + i + "'")
answer = input("You: ")
specs.append(answer)
else:
print("System: 'Sorry, this troubleshooting program does not support that device.'")
try:
problems(specs[0], specs[1], specs[2], specs[3], specs[4], specs[5])
except IndexError:
pass
print("System: 'The program has ended.'")
case.close()
我曾尝试在try块中加入一些印花和不打印出来。只有finally块正在运行,这显然会抛出一个错误,因为caseNum没有被定义为它在try/except块中定义的。 (这是def的尝试,这里是问题)。
答
不确定,但我认为“**如果”不是有效的,并且在它后面的所有内容都是混淆的。
+0
对不起,我试图使它大胆,它只是补充说 –
请把它降低到[mcve]。你可以在这个过程中解决你自己的问题。 – jonrsharpe
你能给我们一个样本输入来运行这个方法吗? – gowrath
我只收到finally块的错误信息,因为try块没有运行,我可以看到“...”没有为try块打印输出。 –