I tried to compare the key and value values from the Python list, but the conditional statement doesn't work.

Asked 2 years ago, Updated 2 years ago, 14 views

ho = {'aaaa':1111, 'bbbb':2222, 'cccc':3333} Please enter print('ID'.') a = input() if a in ho: print('Please enter your password.') else: print ('There is no such ID')

Please enter the
print('password'.')

b = input() password = ho[a] if password == b:
print("You have successfully logged in."), else: print("!!Login failed!!")

It keeps saying that I failed... The password value is 1111 and the input value of b is 1111 Why doesn't the conditional statement work...

python

2022-09-22 08:34

1 Answers

If you enter b = input(), the string '1111' is in b It's different from the integer 1111.

b = int(input())

Change to or change the value to a string

'aaaa':'1111'


2022-09-22 08:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.