所以我在使用 Python 时遇到了一个奇怪的问题,它与 try 和 except 函数有关。它应该允许我重新输入客户,在这种情况下是 c2,因为 c1 正在将资金转移到 c2。但是,它给了我一个关键错误,而不是说用户不在数据库中并要求我重新输入客户名称。尽管存在视觉错误而不是功能错误,但在下面的代码中第二次使用 try 和 except 仍然有效。
我尝试更改我使用 try 和 except 的位置,并尝试在线搜索但没有找到解决方案。我只使用 Python 几个月,它就在那个时候断断续续。
elif option == 3:
print("Option", 3)
try:
c2 = input("Customer 2")
customer2 = BankSystem.c[c2]
except ValueError:
print("\n>>>An exception occured ~ invalid i/p")
print("\t~Customer not in database")
print()
if "c2" in BankSystem.c: ## check for valid account id
print(customer2)
try:
amount = float(input("Amount to transfer "))
self.tranfer(customer2, amount)
except ValueError:
print("\n>>>An exception occured ~ invalid i/p")
print("\t~Non-numeric data entered")
else:
print("\n>>>>>>>account:{} does not
exist".format("c2"))
print(self)
print(customer2)
德玛西亚99
30秒到达战场
相关分类