What is wrong with this code??
Can you tell what it does??
import art
n1 = 0
n2 = 0
selected_operation = ""
solution = 0
def add(n1, n2):
return n1 + n2
def subtract(n1, n2):
return n1 - n2
def multiply(n1, n2):
return n1 * n2
def divide(n1, n2):
return n1 / n2
operations = {
"+": add,
"-": subtract,
"*": multiply,
"/": divide
}
def rest_of_calculation():
print("+\n-\n*\n/")
selected_operation = input("Pick an operation: ")
n2 = float(input("What is the next number?: "))
for key in operations:
if key == selected_operation:
solution = operations[key](n1, n2)
print(f"{n1} {key} {n2} = {solution}")
print(art.logo)
n1 = float(input("What is the first number?: "))
rest_of_calculation()
while True:
new_calculation = input(f"Type 'y' to continue calculating with {solution}, or type 'n' to start a new calculation: ")
if new_calculation == "y":
n1 = solution
else:
n1 = float(input("What is the first number?: "))
rest_of_calculation()
Comments
Post a Comment