0
What is the alternative of if-elif-else statements in this code?
2 Answers
+ 3
An alternative could be defining all options as methods (using def for each of them). Then, making a dictionary with possible input as keys and method calls as values:
def check_balance():
...
d = {'1': check_balance, ...}
u = input()
if u in d:
d[u]()
else:
print('Wrong choice')
EDITED, thanks HonFu!
+ 2
Kuba SiekierzyĆski, wouldn't it have to go like this?
d = {'1': check_balance, ...}
u = input()
if u in d:
d[u]()
else:
print('Wrong choice')