代码结束时,在Python中再次启动该函数
我创建了一些代码代码结束时,在Python中再次启动该函数,python,Python,我创建了一些代码 def Basket(): #the start of the code items1=[] items1=input("type items\n") options=int(input("choose options\n")) if options==1: print("items on basket are:\n", items1) elif options==2: print(items1
def Basket(): #the start of the code
items1=[]
items1=input("type items\n")
options=int(input("choose options\n"))
if options==1:
print("items on basket are:\n", items1)
elif options==2:
print(items1.count(',')+1) #the end
Basket()
我想一次又一次地使用这个程序,而不是关闭它
所以我需要程序在结束后一直转到代码的开头
帮助?简单地说:
def Basket(): #the start of the code
while True:
items1=[]
items1=input("type items\n")
options=int(input("choose options\n"))
if options==1:
print("items on basket are:\n", items1)
elif options==2:
print(items1.count(',')+1) #the end
Basket()
或者(正如@zvone所评论的)
或者(优雅地)
为True:Basket()
?
def Basket(): #the start of the code
items1=[]
items1=input("type items\n")
options=int(input("choose options\n"))
if options==1:
print("items on basket are:\n", items1)
elif options==2:
print(items1.count(',')+1) #the end
while True: Basket()
def Basket(): #the start of the code
while input("add an item ? (y:Yes or n:No) \n") == "y":
items1=[]
items1=input("type items\n")
options=int(input("choose options\n"))
if options==1:
print("items on basket are:\n", items1)
elif options==2:
print(items1.count(',')+1) #the end
Basket()