Home > Software engineering >  looping a function with different arguments in python
looping a function with different arguments in python

Time:11-30

I am trying to loop over a function with different numbers as arguments. I want to test the numbers between 1 and 20 for example. What is the way to go?

def calculation(w):
     print_me_w = w 1
     print (print_me_w)

calculation(1)

CodePudding user response:

You can use the range function for this.

def calculation(w):
    print_me_w = w 1
    print (print_me_w)

for i in range(1,21):
    calculation(i)

CodePudding user response:

You can use range builtin and for loop as follow:

for i in range(1, 21):
    calculation(i)
  • Related