【发布时间】:2018-02-08 20:22:57
【问题描述】:
我是一个 python 菜鸟,试图获取一个变量,将其与字典键匹配,然后返回匹配键的值。如果不匹配,则继续循环。目标是创建一个粗略的用户数据库,以便用户输入可以选择对应的同名类实例。
我收到语法错误: 如果名称 == 帐户列表 []: SyntaxError:无效的语法(指向第二个 [])。是否有语法可以使这项工作,或者我在这里偏离基地?提前感谢您的帮助。
class BankAccount():
balance = 0.0
account_owner = ""
def welcome(self):
print("Welcome, " + self.account_owner.name + "!")
account_list = {
"Matty": mattyAccount
"Hannah": hannahAccount
..etc
}
name = input("Enter Username:\n")
while name != account_list[]:
print("Not recognized.")
else:
account_list[name].welcome()
【问题讨论】:
-
有什么问题?
-
你希望
account_list[]是什么?
标签: python python-3.x dictionary