Spaces: when defining or using variables, you often have it like
var= "value"
. To avoid confusing it with Bash and keep it consistent, have one space before and after the equals operator, likevar = "value"
.elif
vsif
: when more than oneif
statements are used (i.e.--if an operation or function requires two or more conditionals for ONE situation) useelif
to describe the other conditionals. This makes your code much more efficient--withif+elif
, if one condition is satisfied, the interpreter will not check the otherifs
once any of the condition has been satisfied. However, if you use multipleif
statements for the same set of conditionals, then it will check the otherif
statements, even if one has already been satisfied. This can lead to buggy code. See herehere for a similar question.while True
: This could be changed towhile inputted_password != password_compare
to shorten the code and remove theif
statement. Your way is just as efficient, however, so it doesn't really matter if it is changed.As mentioned before, functions should go BEFORE your code.
Globalizing: When globalizing variables, the
global
command goes at the top of the function, before any code.Whitespace: I for one don't really care about tabs vs. spaces, but there are some examples of whitespace that are imperative for readability. Keep space between top level sections of code (like imports, functions, and pre-sections of code) to improve readability.
Commenting: This code is fairly pleasant to read. However, a little commenting goes a long way! It is also good practice to describe your functions with docstrings.