Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python returns blank when trying to make a loop using def keyword (CLOSED)

I don’t know how to explain this.. Uhh..
So i wanted to make the terminal repeat my code but when i realized what i had to do, i did it, but after i ran the code, it just appeared blank, there is nothing appearing, i am pretty new to python so i came here to ask, anyways, heres my code:

def termi():
    username=input("input username= ")
    to_deny = "!? /,.[]()"
    if any(char in username for char in to_deny):
        print("denied characters: ?, !, space(s), /, dots, [], ()")
        quit()
    elif len(username) <= 2:
        print("username must be at least 3 characters")
        quit()
    else:
        print(f"hello {username}!")
        cmd=input("command: ")
    if cmd=='print':
        printer=input("input print:")
        print(printer)
    elif cmd=='help':
        print("commands: print, help, close/quit, sysver, date+time")
    elif cmd=='close':
        print("closing")
        quit()
    elif cmd=='quit':
        print("quitting")
        quit()
    elif cmd=='help print':
        print("usage: print (args)")
    elif cmd=='help close':
        print("usage: close")
    elif cmd=='help quit':
        print("usage: quit")
    elif cmd=='sysver':
        print("system version: 0.4 beta")
        print("latest update: 1:18 am (pst) on june 18th")
    elif cmd=='date+time':
        import datetime
        time=datetime.datetime.now()
        print(f"the date+time is: {time}")
    else:
        print("invalid!")
def again():
    terminal = input("run terminal again?")

    if terminal == 'Y':
        termi()
    elif terminal == 'N':
        quit()
    else:
        again()

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Do NOT use recursion like this. That’s not what it was designed for. Instead:

def again():
    while True:
        terminal = input("run terminal again?")

        if terminal == 'Y':
            termi()
        elif terminal == 'N':
            return

again()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading