0

In my code, the 'detentions' integer seems to be taking the value of the 'day' integer when calling new_week()

I have looked through the code and just cannot find what is causing it.

It is defined like:

def new_week(self, detentions, motivation):
  print(colored(detentions, 'yellow'))
  oldmotiv = motivation
  for i in range(0, detentions):
    motivation = motivation - 3
    print(colored("Detentions: " + str(detentions), 'yellow'))
    print(colored("Motivation: " + str(motivation), 'yellow'))

  print(colored("End of week summary: ", 'green'))
  lostmotiv = oldmotiv - motivation
  print(colored("You lost " + str(lostmotiv) + " motivation!", 'green'))
  detentions = 0

It is invoked like:

  print("It's the weekend! What would you like to do?")
  WorldSettings.new_week(detentions, day, motivation)
  again = input("Continue? yes, no ")
  again.lower()
  day = 1

Full code is here, on Repl.it

Daniel
  • 21,933
  • 14
  • 72
  • 101
2tbc1887
  • 3
  • 1
  • 5

1 Answers1

1

In your code you are invoking the method as if it were a class method:

WorldSettings.new_week(detentions, day, motivation)

It should be as an instance method:

class_worldsettings.new_week(detentions, day, motivation)

Also, notice that you are invoking the method with 3 parameters, but your method is defined to only need 2 parameters (besides the elf`that is an implicit parameter):

def new_week(self, detentions, motivation)

So it should be:

def new_week(self, detentions, day, motivation)
Daniel
  • 21,933
  • 14
  • 72
  • 101
  • Thanks so much! Do you know why that occurs? – 2tbc1887 Nov 23 '18 at 01:34
  • What occurs? The extra `self` argument? That's a reference you use to access other methods and fields on the instance where you are invoking this method. Check this other post that explains it well: https://stackoverflow.com/questions/2709821/what-is-the-purpose-of-self – Daniel Nov 23 '18 at 17:22