Реакция на input по значению в словаре
Вопрос от новичка Python
Ничего не выводит.
Хотя пишу в 'user' -> Привет
vocabulary = {
'hello': ('Привет' , 'привет' ,)
}
user = input('Enter: ')
if user == 'hello' :
print('Hello')
Ответы (2 шт):
Автор решения: S. Nick
→ Ссылка
Попробуйте так:
vocabulary = { 'hello': ('Привет' , 'привет' ,) }
user = input('Enter: ')
#if user == 'hello' : print('Hello')
if user in vocabulary['hello']:
print('Hello')
Автор решения: Namerek
→ Ссылка
vocabulary = {
'привет': 'hello'
}
user = input('Enter: ')
print(vocabulary[user.lower().strip()] if user.lower().strip() in vocabulary else None)
