0

In this code, I want to execute try again when an exception occurs.

What are the various ways?

type_input = 0

print("Welcome to the fantastic Mud Shopping Mall, MADMUDSHOP!!")
print("(Select your member type.)")
print("1. Administrator \t 2. User ")

command = {
    1 : print_admin_home,
    2 : print_user_home
}

type_input = int(input())


try:
    command[type_input]()
except KeyError:
    print("You mistyped it!")
Nemomong
  • 21
  • 6

1 Answers1

1

You put it in a while loop, that will loop forever :

command = {1: print_admin_home, 2: print_user_home}
print("Welcome to the fantastic Mud Shopping Mall, MADMUDSHOP!!")
while True:
    print("Select your member type:\n1. Administrator \n2. User")
    type_input = int(input())
    try:
        command[type_input]()
    except KeyError:
        print("You mistyped it!")
azro
  • 53,056
  • 7
  • 34
  • 70