我不知道如何解釋這個..呃..所以我想讓終端重復我的代碼但是當我意識到我必須做什么時,我做到了,但是在我運行代碼之后,它只是顯示為空白,什么都沒有出現,我對python很陌生,所以我來這里問,無論如何,這是我的代碼:
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()
uj5u.com熱心網友回復:
不要像這樣使用遞回。這不是它的設計目的。反而:
def again():
while True:
terminal = input("run terminal again?")
if terminal == 'Y':
termi()
elif terminal == 'N':
return
again()
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/495438.html
標籤:Python python-3.x
上一篇:以下SQL查詢的說明
