import random
state = 1
balance = random.randint(500,2500)
print (balance)
accounts= {
"swindrunner" : "1234",
"istormrage" : "abcd",
"tpgallywix" : "qwerty"
}
print (state)
while state == 1:
print (state)
userpass = ["swindrunner1234", "istormrageabcd", "tpgallywixqwerty"]
username = input("Username:")
password = input("Password: ")
#AccountInfo = username + password
print(userpass)
break
AccountInfo = username + password
state = 2
print(state)
while state == 2:
print(state)
print(AccountInfo)
if AccountInfo == "swindrunner1234" or "istormrageabcd" or "tpgallywixqwerty":
print ("ok")
state = 3
else:
print ("no")
state = 1
break
print(state)
while state == 3:
input("Display, Withdraw, Deposit, Exit")
why is the code going to state == 3 if the AccountInfo isn’t one of the 3 that its supposed to be equal to? shouldn’t the if else statement set the state == 1 if AccountInfo is incorrect?
the issue is with the if conditional statement. It is true for any string, float or integer.
AccountInfo = 8.55 # Substitute with any "int","float" or "string" value and
# observe which "if" conditional statement is executed
# Original method not working - do not use - true for any value
if AccountInfo == "swindrunner1234" or "istormrageabcd" or "tpgallywixqwerty":
print('Via original method, AccountInfo is: ', AccountInfo)
# Use this method
if AccountInfo in ("swindrunner1234", "istormrageabcd", "tpgallywixqwerty"):
print('Via second method, AccountInfo is: ', AccountInfo)