Created
February 9, 2018 16:24
-
-
Save NateAllCodey/7405de9f0a4de69c1cdb256426fabb7a to your computer and use it in GitHub Desktop.
Python Trig Calculator (I need Help)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import random | |
def askForNumInput(textPrompt): | |
# Devine local variable | |
convertedNum = math.nan | |
# Wait for valid numerical input | |
while True: | |
num = input(textPrompt) | |
try: | |
# Try to typecast the input to a float | |
float(num) | |
except ValueError: | |
# Catch the exception if it is not a number | |
print("ERROR: Syn: Invalid Num") | |
else: | |
# Typecasting | |
convertedNum = float(num) | |
break | |
return convertedNum | |
def abilitiesList(): | |
print("+...Addition") | |
print("-...Subtraction") | |
print("*...Multiplication") | |
print("/...Division") | |
print("^...Powers") | |
print("/-...Square Roots ") | |
print("!...Factorials (Input Cannot Be Negetave)") | |
print("Abs...Absolute Value") | |
print("d/r...Degrees To Radians") | |
print("r/d...Radians To Degrees") | |
print("pi...Returns PI") | |
print("e...Returs 'e'") | |
print("tau...Returns TAU (2xPI)") | |
print("M+...Save input to memory") | |
print("MR...Recall Memory") | |
print("M-...Clear Memory") | |
print("sin...Sine") | |
print("cos...Cosine") | |
print("tan...Tangent") | |
print("asin...Arc Sine") | |
print("acos...Arc Cosine") | |
print("atan...Arc Tangent") | |
print("log10...Log(10) of Input") | |
print("log...Returns The Apropriate Log of the Input (input1 is the log power)") | |
print("rand...Returns A Random Number Between 0 and 1") | |
print("randint...Returns A Random Number Between The Two Inputs") | |
print("//////////////////////////////////////////////////////////////////////////") | |
print("Type 'help' for a list of abilities") | |
while True: | |
operator = input("What operation do you want to perform? ") | |
# Is operator == to any of out constants or predefines? | |
if operator == "help": | |
abilitiesList() | |
elif operator == "pi": | |
print(math.pi) | |
elif operator == "e": | |
print(math.e) | |
elif operator == "tau": | |
print(math.pi*2) | |
elif operator == "MR": | |
print(str(memStore)) | |
elif operator == "M-": | |
memStore = "Empty" | |
print("Memory Cleared") | |
elif operator == "rand": | |
print(random.random()) | |
if operator == "+": | |
output = num1 + num2 | |
print("Your Answer: "+str(output)) | |
elif operator == "-": | |
output = num1 - num2 | |
print("Your Answer: "+str(output)) | |
elif operator == "*": | |
output = num1 * num2 | |
print("Your Answer: "+str(output)) | |
elif operator == "/": | |
output = num1 / num2 | |
print("Your Answer: "+str(output)) | |
elif operator == "^": | |
output = math.pow(num1,num2) | |
print("Your Answer: "+str(output)) | |
elif operator == "/-": | |
output = math.sqrt(num1) | |
print("Your Answer: "+str(output)) | |
elif operator == "!": | |
output = math.factorial(num1) | |
print("Your Answer: "+str(output)) | |
elif operator == "Abs": | |
output = math.fabs(num1) | |
print("Your Answer: "+str(output)) | |
elif operator == "d/r": | |
output = math.radians(num1) | |
print("Your Answer: "+str(output)) | |
elif operator == "r/d": | |
output = math.degrees(num1) | |
print("Your Answer: "+str(output)) | |
elif operator == "M+": | |
memStore = num1 | |
print("Number Stored") | |
elif operator == "sin": | |
output = math.sin(num1) | |
print("Your Answer: "+str(output)) | |
elif operator == "cos": | |
output = math.cos(num1) | |
print("Your Answer: "+str(output)) | |
elif operator == "tan": | |
output = math.tan(num1) | |
print("Your Answer: "+str(output)) | |
elif operator == "asin": | |
output = math.asin(num1) | |
print("Your Answer: "+str(output)) | |
elif operator == "acos": | |
output = math.acos(num1) | |
print("Your Answer: "+str(output)) | |
elif operator == "atan": | |
output = math.atan(num1) | |
print("Your Answer: "+str(output)) | |
elif operator == "log10": | |
output = math.log10(num1) | |
print("Your Answer: "+str(output)) | |
elif operator == "log": | |
output = math.log(num2, num1) | |
print("Your Answer: "+str(output)) | |
elif operator == "randint": | |
output = random.randint(num1, num2) | |
print("Your Answer: "+str(output)) | |
break | |
else: | |
print("ERROR: Invalid Operator") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When I run it it comes up with errors. Can anyone help me fix these errors?