+ 1

how to loop a def function for 3 accounts

I was able to create my working function. Now I need to loop it and print each account. Next I need to compare them. My problem is not knowing how to loop the function and keep each variable. Please help me Loop.

1st Feb 2022, 5:21 PM
Esther McAngus
8 Answers
0
I think that the variables that you need in each iteration are going to have to be passed to your function as an argument. otherwise you would have to loop inside the function rather than call it multiple times
1st Feb 2022, 5:58 PM
CGM
CGM - avatar
+ 2
Could you share the code? Let's see if I understood You want to call the function more than once without losing the function's local variables?
1st Feb 2022, 5:26 PM
CGM
CGM - avatar
+ 1
l = [] for i in range(3) : l[i] = def_func() # is this you mean ?
1st Feb 2022, 5:26 PM
Jayakrishna 🇼🇳
1st Feb 2022, 5:40 PM
Esther McAngus
+ 1
Also I would like to change change the 1st print statement. Saying "account 1" iterating to "account 2", account 3
1st Feb 2022, 5:42 PM
Esther McAngus
0
No idea how the code works or what it does, but here's a loop ÂżThis is useful? https://code.sololearn.com/c04yxjWe6NOH/?ref=app
1st Feb 2022, 5:50 PM
CGM
CGM - avatar
0
It as a program that takes def summary(months subscribed=m, adfree months subscribed = a, video on demand purchases = v) I need to repeat this function for 3 different accounts with the local variables
1st Feb 2022, 5:54 PM
Esther McAngus
- 1
yes I need the local variables
1st Feb 2022, 5:36 PM
Esther McAngus