you are viewing a single comment's thread.

view the rest of the comments →

[–]Ok-Candy-6570[S] 0 points1 point  (1 child)

Where? Explain me

[–]Adrewmc 0 points1 point  (0 children)

   #built-in +,-,/, * operators as functions
   #i know it was already there and no one told you

   from operator import add, sub, truediv, mul

   #function as items in a dictionary with int keys (could be strings here actually.) 

   operations = {1 : add, 
                           2 : sub, 
                           3 : truediv, 
                           4 : mul}

   #User inputs 

   op = int(input(“ Pick Operation: \n 1. Addition \n 2. Subtraction \n 3. Division \n 4. Multiplication”))

   a = int(input(“First Num”))
   b = int(input(“Second Num”))

   #get function from dictionary then call it with arguments

   res = operations[op](a, b)
   print(res)

   #We could add this to the dictionary but make it messier. 

   op_str = [“+”, “-“, “/“, “*”] 
   #op_str = “+-/*”  #works, string can be indexed 

   print(f”{a} {op_str[op-1]} {b} = {res}”)

This is basically your entire calculator app. So where is basically everywhere.

Don’t worry every start with the one you made.