簡體   English   中英

我怎樣才能重復這個程序

[英]How Can I repeat this program

仍然,一個絕對的初學者沒有找到一個正確的方法來重復這個我需要重復這個程序沒有for循環我只需要 go 啟動程序一次並打印 output

    dic = {10200:"Homagama" , 10206:"Pitipana" , 10101:"Athurugiriya" , }
a = input("Enter Postal Code:")

if int(a) in dic:
    print(dic[int(a)])

else:
    print("Not in our DB")

由於您不想使用循環,您可以使用 go 進行遞歸 function (這是一個 function 基本上在某個時間點調用自己)

def func():
        dic = {10200:"Homagama" , 10206:"Pitipana" , 10101:"Athurugiriya"}
        a = input("Enter Postal Code:")
        if int(a) in dic:
            print(dic[int(a)])
        else:
            print("Not in our DB")
        if condition_of_repeating:# when you want to repeat
            func()
func()

盡管明確建議使用簡單的循環。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM