I am currently working on a Python project. It is some sort of a hub, where you can do some cool but basic stuff, such as: setting timers, launching websites, doing basic math, ping and view source codes of URLs, and more.
I want to make this code just a little more compact. I especially want my math menu more compact because I feel there is a way of doing it. I just can't seem to figure it out.
…
elif userIn == ("math"):
op = str(input(" * Enter operation (+, -, *, /, exp, sqrt, log): "))
blank()
if op==("+") or op==("-") or op==("*") or op==("/") or op==("exp"):
input_1 = int(input(" * Enter first number: "))
blank()
input_2 = int(input(" * Enter second number: "))
blank()
if op == ("+"):
print (" > "+str(input_1 + input_2))
blank()
elif op == ("-"):
print (" > "+str(input_1-input_2))
blank()
elif op == ("*"):
print (" > "+str(input_1*input_2))
blank()
elif op == ("/"):
print (" > "+str(input_1/input_2))
blank()
elif op == ("exp"):
print (" > "+str(input_1**input_2))
blank()
elif op == ("sqrt"):
oneInput=int(input(" * Enter number: "))
blank()
print (" > "+str(math.sqrt(oneInput)))
blank()
elif op == ("log"):
input_1 = int(input(" * Enter number: "))
blank()
input_2 = int(input(" * Enter base: "))
blank()
print (" > "+str(int((math.log(input_1, input_2)))))
blank()
Note: I have tried setting a basic for loop run through a list of operation symbols, and it would set the operation if the user op. was matched. But, as it turns out, I just couldn't use strings as math operators in the code itself.
opl=["+", "-", "*", "/"]
for i in range(len(opl)):
userInput1 (some way of setting op) userInput2