Skip to content

Tag: if-statement

Run Loop If Value Does Not Exist in Database

#update – I fixed the syntax error moving a ), but it still doesn’t work as intended. Now it runs the loop even with a duplicate, which is not the intent. I’m trying to add a list of quotes to a database, but only if the author doesn’t already exist. I’m getting a syntax error he…

elif: SyntaxError: invalid syntax

I want to re.search within an if statement but regardless of identation, get syntax error. Is it because elif: has no condition? error message Answer In elif you have if, it requires a condition and you provide none, it should be Using walrus operator (since py3.8) you can improve your code to look like If th…

Cleaner Alternative to Nested If/Else

I’m mainly focused on an alternative to if/else’s in create_animal. If there is a more professional way to handle this. In this case, it’s a classifier based on a variable number of traits needed to figure out what the animal is. Since humans are the only animals that speak English, that pro…