i get the error traceback (most recent call last): File "main.py", line 64, in print(f" {num_1} {operation} {num_2} = {answer}") NameError: name 'answer' is not defined
idk why, tho. this code was working very well, so i didnt touch it. but as sson as i tried other mathematical operations it broke.
#inputs and stuff VV
num_1 = input("What's Your First Number?: ")
operation = input(" + \n - \n * \n / \n Pick An Operation: ")
num_2 = input("What's Your next Number?: ")
#functions
def addition():
answer = int(num_1) + int(num_2)
def subtraction():
answer = int(num_1) - int(num_2)
def multiplication():
answer = int(num_1) * int(num_2)
def division():
answer = int(num_1) / int(num_2)
def continue_prog():
print(answer)
operation = input(" + \n - \n * \n / \n Pick An Operation: ")
new_num_2 = input("What's Your next Number?: ")
print(f" {answer} {operation} {new_num_2} = {answer}")
def Continue_or_not():
continue_or_not = input(f"Typer 'Y' to Continue Calculating With {answer}. \n Or Type 'N' To Begin New Operation \n Or 'C' To Close The Calculator: ")
if continue_or_not == "Y":
continue_prog()
if continue_or_not == "N":
clear()
answer = 0
num_1 = input("What's Your First Number?: ")
operation = input(" + \n - \n * \n / \n Pick An Operation: ")
num_2 = input("What's Your next Number?: ")
else:
exit()
#computer checking which operation was picked
def chosen_operation():
if operation == '+':
addition()
if operation == "-":
subtraction()
if operation == "*":
multiplication()
if operation == "/":
division()
chosen_operation()
#Actual Code
print(f" {num_1} {operation} {num_2} = {answer}")
continue_or_not = input(f"Typer 'Y' to Continue Calculating With {answer}. \nOr Type 'N' To Begin New Operation \nOr 'C' To Close The Calculator: \n")
if continue_or_not == "Y":
continue_prog()
if continue_or_not == "N":
clear()
else:
exit()
please help, i need this so i can impress my mother.
i tried deleted a variable i had, which was (answer = 0 ) so new variables can be put in the empty answer variable. but it broke the code more