Wheel Orange
Wheel Orange

Reputation: 1

Why it isnt adding the numbers?) (problem with return value)

I was trying to make a calculate but return doesnt work (Its an uncomplete code but iam an answer could solve it all )





def plus(num1, num2):
  return num1 + num2

symbols = {
"+":plus
  
}

num1 = int(input(": "))
num2 = int(input(": "))

symbol = input("symbol: ")

count = symbols[symbol]
count = (num1, num2)

print(count)

Upvotes: 0

Views: 37

Answers (1)

Matthias
Matthias

Reputation: 13222

symbols contains a mapping from an operator to a function. You have to get this function, call it, and display the result.

def plus(num1, num2):
    return num1 + num2

symbols = {
    "+": plus,
}

num1 = int(input(": "))
num2 = int(input(": "))

symbol = input("symbol: ")

function = symbols[symbol]
result = function(num1, num2)

print(result)

As it is, this only handles the + operator. You might want to add some more operations and maybe an error handler for unknown symbols.

Upvotes: 1

Related Questions