Real life usage of Assertion and try/except in program.
def d2w(n): dicts = { 1 : "One", 2 : "Two", 3 : "Three", 4 : "Four", 5 : "Five", 6 : "Six", 7 : "Seven" } return dicts[n] while True: ui = input("Enter a number: ") try: assert 0 < int(ui) <= 7 print(d2w(int(ui))) except AssertionError: print("Number should be between 1 and 7") except ValueError: try: assert ui.lower() == "stop" print("Bye!") break except AssertionError: print("U didn't Entered INT or Stop") # This program takes number as input converter it to words and when it stop when user input "stop". # While writing this code i realised that if-else conditions can be replaced with Assertion and try/except at least for checking user input. ***You query or suggestions is highly appreciated.