获取python 3+比较返回值和输入值
自从我使用python以来已经有好几个月了。我没有得到一个错误,但我也没有收到所需的输出。获取python 3+比较返回值和输入值
我有一个函数:
def set_account(gather_accounts):
print("gather_accounts():\n")
for a in gather_accounts:
print('Value: {}'.format(a[1]))
if decision_enter_account == 'Y':
bool_add_account = True
while bool_add_account == True:
prompt_account_url = input('What is the account\'s url?\n')
prompt_account_name = input('\nWhat is the account name? \n')
#TODO check for duplicate account names, and disallow
for a in gather_accounts:
if prompt_account_name == a[1]:
print('Sorry you already had an account with {} try again.\n'.format(prompt_account_name))
prompt_account_name = input('\nWhat is the account name? \n')
我试着去实施对返回值gather_accounts
重复检查,具体而言,在for
循环a[1]
变得像Chase
但是一个值,当我运行这个脚本,如果我输入Chase
它没有命中:if prompt_account_name == a[1]
我该如何解决这个比较用户输入的val ue的prompt_account_name
并将其与a[1]
的值进行比较?
感谢
我猜你是在Python2运行,如果Python2,你需要在这种情况下使用prompt_account_name = raw_input('\nWhat is the account name? \n')
而不是prompt_account_name = input('\nWhat is the account name? \n')
。
实际上,在Python3中,input()
相当于Python2中的raw_input()
。 虽然在Python3中删除了raw_input()
。
它绝对是Python3 –
如果OP使用2.7,我期望他得到一个异常'NameError:name'Chase'没有被定义。但他说他没有得到一个错误。 – Kevin
请提供证明问题的[mcve]。 – Kevin
'gather_accounts'是两个字符串的元组列表吗? –
这段代码适合我。你能说明你如何创建gather_accounts以及你正在运行什么版本的Python? –