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 :
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()