Taschenrechner

--Originally published at PYTHON 3

A time ago I made a little project, which is kind of a pocket calculator. A program that lets you make additions, subtractions, divisions and multiplications. Let’s see how that works…

I wanted a nice menu, a nice welcome to my program, for that I made some prints at the beginning to, and immediately the menu options.

Each option has a number (1,2,3,4)

(1) Addition

(2) Subtraction

(3) Multiplication

(4) Division

And to select an option I made an input variable, now the user gets the option to choose whatever operation he wants, this is the part we go to the ifs, my first if is if the variable is equal to the option 1 (Addition), so if the user had select the number one the instructions on the if will run which is a print with instructions for the user, two input variables for the numbers to add and at the end a print to show the result. All this procedure is the same with the other options in the calculator, but now instead of using if we a re using elif, but if the user is a smart ass and declares a number which is neither of the input options there is an else which will print that there has been an error and will ask the user to try it again.

After the math operation its done and the result has been shown on the terminal, my program will ask the user if he wants to make another operation, for that I made another print menu.

print(“Want to make another operation?”)

print(“(1) Yes”)

print(“(2) No”)

 

If the user wants to make another operation then we need to run all of our code again, that’s why I used a while at the beginning of

selection_003
selection_004
selection_005
selection_007
?
code. with this characteristic.

loop =1:

while loop ==1: 

(The program starts)

…….

      print(“Want to make another operation?”)

      print(“(1) Yes”)

      print(“(2) No”)

      answer = int(input(“Yes or no?”))

      loop = answer 

      if loop == 2:

      break

And that’s it, here are some photos of my code…

selection_003

selection_004

selection_005

selection_007

?