+ 1

Can anyone shorten this code with explanation!

https://code.sololearn.com/cpXpVG2hSJtL/?ref=app

23rd May 2020, 7:42 PM
ROHIT PRADHAN
ROHIT PRADHAN - avatar
2 odpowiedzi
+ 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
23rd May 2020, 8:40 PM
Ali Abdelhady
Ali Abdelhady - avatar
+ 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.
23rd May 2020, 8:05 PM
rodwynnejones
rodwynnejones - avatar