Recursive, asking the way function

 Recursion is to call itself, return can end the loop, print is useless,

def clc(n):
    print(n)
    if int(n/2)==0:
        return n
    res=clc(int(n/2))
    return res
clc(10)
import time
person_list = [ ' cat ' , ' dog ' , ' fish ' , ' jerry ' ] # 1 
def ask_way(person_list):
     if len(person_list) == 0: #To   judge whether it is empty, it can also be understood as when no one is there 
        return  ' i dont know ' 
    person = person_list.pop(0) #Pop   up one person at a time to texture 
    if person == ' jerry ' :   #If the last person in the list is asked 
        return  ' %s say turn aroud the road '% person #guide the road 
    print ( ' hi,%s ,where the road ' % person) #list loop 
    print ( ' %s say i dont know,you can ask %s ' % (person, person_list)) #someone does n't Know that you can ask the rest of the people 
    time.sleep(1) # 1 second 
    return ask_way(person_list) #reduce the size of the question 

res =ask_way(person_list) #the person who started the pattern 2 
print (res)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324933880&siteId=291194637