Python Recursion: Range

后端 未结 5 1000
小鲜肉
小鲜肉 2021-01-26 05:14

I need to define a function called rec_range(n) which takes a natural number and returns a TUPLE of numbers up to the number n.

i.e. rec_range(5) returns (0,1,2,3,4)

5条回答
  •  猫巷女王i
    2021-01-26 05:38

    this is simple one:

    def getrange(a,b,c=1): 
         if a < b: 
            print(a)
            a+=c  
            getrange(a,b,c)
        else:
            return
    
    getrange(0,30,2)
    

提交回复
热议问题