擅长:python、mysql、java
<p>根据提供的示例,我能够使所有条件正确工作</p>
<p><strong>代码如下:</strong></p>
<pre><code>
test_dict = [{"account_number": 12345, "Name" : "Nick", "Last_Name" : "Davis"},
{"account_number": 76531, "Name" : "Carl", "Last_Name" : "Maison"},
{"account_number": 75321, "Name" : "Mary", "Last_Name" : "Depp"},
{"account_number": 12345, "Name" : "Gary", "Last_Name" : "Davis"},
{"account_number": 45896, "Name" : "Jessica", "Last_Name" : "Johnson"},
{"account_number": 12345, "Name" : "Kathy", "Last_Name" : "Davis"}
]
acc = input("Insert Account Number: ")
result_list = []
for i in test_dict :
try:
if int(acc) == i["account_number"]:
result_list.append(i)
elif len(acc) != 5:
print(f"There are 5 digits in the Account Number, you inserted {len(acc)}. Try again.")
break
except:
print("There are no letters in Account Number. Please Insert 5 digits.")
break
else:
if len(result_list) == 0:
print(f"Sorry, Could not find Account Number {acc}. Try again.")
</code></pre>