+ 1
Can anyone shorten this code with explanation!
2 ответов
+ 1
If your code uses a lot of if and else, then it is not the best way to do this, also defining a variable chances is not a good choice (not necessary), you could have used a for loop with range(3) which would give the three chances you desire, no need for "if input_number in (number, number, number, number)" you can define a list of options and check if the input belongs to it or simply use the equality operator '=='.
Also using dictionaries might be a useful in your program, try to find a good use case for it
As you make more progress through the Python course you will encounter different features (just find a way to implement them in your codes) as you practise more you will gain more experience and get to know different ways to do things and that's all about making a code shorter
+ 3
The first thing I would do is :-
i = int(input("Welcome to BANK ATM\nPlease enter your 4-digit PIN\n").replace(' ', ''))
if i == 1234:
#blah blah blah
...you can do the same for some (if not all) of your other inputs too.