So I find that checking user input with multiple if-statements like so is very annoying, ugly, and there seems like a better alternative.
import os
user_input = input(">> ")
if user_input == "clear":
os.system("clear")
elif user_input == "hello":
print("hi!")
else:
print("Option not found")
This can be mitigated by using functions, but is there a way to completely wipe out the if-statements in the first place?
There’s probably a way to do this using classes and methods, but I don’t often use them because I am never sure I’m using them how they’re actually supposed to be used.
user_input = input(">> ")
match user_input:
case "clear":
# Using a print statement because it's faster
print("\033c", end="", flush=True)
case "hello":
print("hi!")
case _:
print("Option not found")