1

I just started learning python since a week.

I am trying to do a testing:


"Beginning of the Program"
print("Hi Sir and welcome to my calculator")
print("Please select from the below menu your math operation")

MenuOption = input("+ for Add, - for Subtract, * for Multiply, / for Division: ") 

if (MenuOption != "+" and MenuOption != "-" and MenuOption != "*" and MenuOption != "/"):
    print("You have typed wrong character, please try again")
    **# my problem is here, I want it to loop back to MenuOption  line**

else:
    print("Thanks for the correct selection")



FirstNumber = int(input("First Number: "))
SecondNumber = int(input("Second Number: "))

if (MenuOption == "+"):
    print(FirstNumber + SecondNumber)

elif (MenuOption == "-"):
    print(FirstNumber - SecondNumber)              

elif (MenuOption == "*"):
    print(FirstNumber * SecondNumber)

elif (MenuOption == "/"):
    print(FirstNumber / SecondNumber)

I want the program to start promoting back the MenuOption, when I don't press any of the math signs (+, -, *, /)

Guga Nemsitsveridze
  • 721
  • 2
  • 7
  • 27
  • 1
    Also see: [1](https://stackoverflow.com/a/18791912/6243352), [2](https://stackoverflow.com/questions/9548070/how-can-i-make-my-program-return-to-the-beginning-in-python), [3](https://stackoverflow.com/questions/28254807/how-to-loop-back-to-the-beginning-of-a-programme-python). [4](https://stackoverflow.com/questions/18791882/how-to-make-program-go-back-to-the-top-of-the-code-instead-of-closing), [5](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) which are all related. – ggorlen May 10 '20 at 05:45
  • Thank you in worked – Mohammed Hashim May 12 '20 at 12:53

1 Answers1

0

You need to learn loops. If you do the thing while the loop expression becomes false, It will be running correctly. Set some variable to false when one of these signs + - / * will be selected, otherwise, the flag variable should be true.

NOTE

That's because of python doesn't support goto and label either

Guga Nemsitsveridze
  • 721
  • 2
  • 7
  • 27