the calculator give me the sum and the subtract [closed]

iam new to python, i was trying to build a calculator, i created sum and subtract but when i do any one of this i always give me the sum and subtract of the numbers

class Math():
  def sum():
      
   if num[1] == "+":
          
    int(num[0]) + int(num[2]) 
      
  def subtract():
       
    if num[1] in numbers == "-":
     int(num[0]) - int(num[2])  
 

numbers = input("> ")
num = numbers.split()



if input(num[1]) == "+":
  print(int(num[0]) + int(num[2]))




if Math.subtract:
  print(int(num[0]) - int(num[2]))


i dont know what to do

  • Change if Math.subtract: to either just else: or elif num[1] == '-':.

    – 

  • In your own words, where the code says if input(num[1]) == "+":, what do you think this should mean, and why? (Hint: what happens when we use input? Do you see that in this line? Do you want to use a new input from the user, or the original input from the user?) In your own words, where the code says if Math.subtract:, what do you think this should mean, and why? What is the actual rule that should tell you, whether to subtract? How would that look in Python code?

    – 

  • 1

    I would strongly recommend that you follow some well structured Python tutorial. See a list of some good ones at sopython.com/wiki/What_tutorial_should_I_read%3F.

    – 

  • why define Math.sum and Math.subtract but never use them, why define them as methods of a class, you are not using Java

    – 

Leave a Comment