1个整数似乎正在采用另一个Python的价值

时间:2018-11-23 01:23:06

标签: python

在我的代码中,调用new_week()时,“扣留”整数似乎采用了“天”整数的值

我看了看代码,只是找不到导致它的原因。

它的定义如下:

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

它的调用方式如下:

  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

1 个答案:

答案 0 :(得分:1)

在您的代码中,您就像在调用类方法一样调用该方法:

char y[5] ={'A','B','C','D','F'};

它应该作为实例方法:

WorldSettings.new_week(detentions, day, motivation)

另外,请注意,您正在使用3个参数来调用该方法,但是将您的方法定义为仅需要2个参数(除了作为隐式参数的elf外):

class_worldsettings.new_week(detentions, day, motivation)

应该是:

def new_week(self, detentions, motivation)