1

im trying to figure out how to make an iterable function in python, since im new to it i would appreciate any help, here is my code :

cra_initial = cra_func(a,b,c)
def cra(cra_initial):
   cra_annum = (cra_initial /7) *365
   'and so on some code contains a, b, c variables above'
   cra_adjusted = cra_func(a,b,c)

as you see in the last line of the code cra_adjusted is using the same function cra_initial in the first line is using, i want to get the result of cra_adjusted and use it as an argument in cra function for like 20 times iterable

4
  • can you provide a minimal reproducible example Commented Dec 28, 2020 at 12:35
  • i think now its more clear Commented Dec 28, 2020 at 13:00
  • This question is about tail recursion and not about iterators. Commented Dec 28, 2020 at 13:04
  • im asking if it could be done by iteration, if not what kind of recursion Commented Dec 28, 2020 at 13:07

2 Answers 2

1

I have found out an easy way of doing it here its

cra_initial = cra_func(a,b,c)
def cra(cra_initial):
    for i in range (1,20):
       cra_annum = (cra_initial /7) *365
      'and so on some code contains a, b, c variables above'

       cra_adjusted = cra_func(a,b,c)
       cra_initial = cra_adjusted

Its more effective

Sign up to request clarification or add additional context in comments.

Comments

0

I think this code would help you.

i=1

def cra_func(a,b,c):
    return (a+b+c)

def cra(cra_initial):
    global i
    cra_annum = (cra_initial /7) *365
    print(cra_annum)
    a,b,c=1,2,3
    cra_adjusted = cra_func(a,b,c)
    i+=1
# This condition will make cra() func run 20 times
    if i<21:
        cra(cra_adjusted)

if __name__=='__main__':
    a,b,c=1,2,3
    cra_initial = cra_func(a,b,c)
    cra(cra_initial)

Rest you can edit accordingly..

2 Comments

Variables must be used accordingly
Please don't make more work for other people by vandalizing your posts. By posting on the Stack Exchange network, you've granted a non-revocable right, under a CC BY-SA license (2.5/3.0/4.0), for Stack Exchange to distribute that content (i.e. regardless of your future choices). By Stack Exchange policy, the non-vandalized version of the post is the one which is distributed. Thus, any vandalism will be reverted. If you want to know more about deleting a post please see: How does deleting work?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.