Remember when I was trying to have a code for “Give a number or give ‘end’ to exit:” “Give a number or give ‘end’ to exit:” Proceeding to the amazing course I am taking our teacher gave the following solution:
Yesterday I wrote the following to ignore numbers inside text. This code does not ignore 123ab but ignores 123.34.
From the code of the previous post for the guessing game: I would proceed to add flags or use the variable given as a flag, e.g.: But then I remembered that loops in python have else clauses so this can be:
In a previous post I used the following code to prompt the user to give a valid number or the string “end”. This code bugged me because there were two prompts, so I replaced it with this one:
Yesterday I realised how useful try/except is, e.g.: gives: ValueError: 4 is not in list So there are two ways to use index:
Yesterday I remembered a problem that I had with the following try/except block. With this code the original error messages were supressed and there was no way I could tell what exactly went wrong. If the file is missing or if it is not a valid zip file the error message would be the same.… Continue reading Keep trying