Error in Python method call (list)

Asked

Viewed 50 times

-3

Good afternoon!

I am receiving an error name 'Month' is not defined because of the last method of this code:

self.calc_months(month_of_year) 

        def year(self, execution_times):
            return [self.month(execution_times, month)]
  • 1

    Please correct the indentation of your code in the question; in Python, as you may know, indentation is paramount for correct interpretation. And checking the implementation of the method year, in fact the object month is not defined. What value it should possess?

  • then, it can only receive a parameter that is execution_times, this year method needs to inform the list with the value of all months, calculated in the previous method

2 answers

0


The example below defines the variable month in a loop that runs through the 12 months (1 to 12).

def year(self, execution_times):
    return [self.month(execution_times, month) for month in range(1, 13)]
  • thank you very much! gave it right.

-1

I reformatted your code and created a routine to use your class:

cost = CloudCost()

for mes in range(1,12):
    print(cost.month(10, mes))

And everything worked normally and the method was invoked:

0.387128
0.349664
0.387128
0.37464
0.387128
0.37464
0.387128
0.387128
0.37464
0.387128
0.37464

Check the indentation of your code.

  • thanks!! I managed to submit the code!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.