0

Is there any simple method to return to menu by entering a special key? If the user made a mistake while entering the input, user can return to main menu by pressing @ (a special key) key at the end of the input.

x = input("Enter first number: ")

Here, user enter 5, but want to exit by input @. So, x = 5@

I tried some including this

x=input("Enter first number: ")
print(int(a))
if x == "@":
exit()

Also tries this too

for x in ['0', '0$']:
    if '0$' in x:
        break

But, unable to handle numbers and string values together.

martineau
  • 119,623
  • 25
  • 170
  • 301
Tommy
  • 1
  • 2

3 Answers3

0
while True:
  x = input()
  if x[-1] == '@':
    continue
  # other stuff

this should work

0

Try

user_input = input("Enter your favirote deal:")
last_ch = user_input[-1]
if(last_ch == "@"):
    continue
else:
    //Your Logic
Nouman Ahmad
  • 102
  • 7
0

int(x) will not work if it contains characters other than numbers. use this construction (@ will be ignored by converting a string to int)

x=input("Enter first number: ")
print(int(x if "@" not in x else x[:-1])) # minus last if has @
if "@" in x:
    exit() # or break or return, depends what you want
Ashgabyte
  • 154
  • 1
  • 5