获取python 3+;返回值与输入值的比较
我已经有好几个月没有使用python了。我没有收到错误,但是我也没有收到想要的输出 我有一个功能:获取python 3+;返回值与输入值的比较,python,string-comparison,Python,String Comparison,我已经有好几个月没有使用python了。我没有收到错误,但是我也没有收到想要的输出 我有一个功能: 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_accoun
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')
我正在尝试根据返回值collect\u accounts
执行重复检查,特别是在for
循环中a[1]
获取类似Chase
但是,当我运行这个脚本时,如果我在Chase
中输入,它不会命中:如果提示\u account\u name==a[1]
如何解决此问题以比较用户输入的prompt\u account\u name
值,并将其与a[1]
中的值进行比较
谢谢我猜您正在Python2中运行,如果在Python2中,您需要使用
prompt\u account\u name=raw\u input('\n帐户名是什么?\n')
而不是prompt\u account\u name=input('\n帐户名是什么?\n')
实际上,在Python3中,input()
相当于Python2中的raw\u input()
。
而Python3中的
raw\u input()
被删除 我猜您正在Python2中运行,如果在Python2中,您需要使用prompt\u account\u name=raw\u input('\n帐户名是什么?\n')
而不是prompt\u account\u name=input('\n帐户名是什么?\n')
实际上,在Python3中,input()
相当于Python2中的raw\u input()
。
而Python3中的
raw\u input()
被删除 请提供一个例子来说明这个问题。gather\u accounts
是两个字符串的元组列表吗?这个片段对我来说很好。你能告诉我你是如何创建gather_帐户的吗?你运行的是什么版本的Python?运行python3+,gather_帐户是另一个函数的返回值。请提供一个例子来说明这个问题。gather_帐户
是两个字符串的元组列表吗?这个片段对我来说很好。你能告诉我你是如何创建gather_帐户的吗?你运行的是什么版本的Python?运行python3+,gather_帐户是另一个函数的返回值它肯定是python3如果OP使用的是2.7,我希望他得到一个异常NameError:name'Chase'没有定义
。但是他说他没有得到一个错误。这肯定是Python3如果OP使用2.7,我希望他得到一个异常NameError:name'Chase'没有定义。但他说他没有犯错误。