【问题标题】:In python, I received this error TypeError: '>=' not supported between instances of 'function' and 'int'在 python 中,我收到此错误 TypeError: '>=' not supported between 'function' and 'int' instances
【发布时间】:2017-10-25 02:30:04
【问题描述】:

到目前为止我的代码:

def book_point():
      displayoints = 0
      books = 0
      setmessage()
      books = bookinput()
      displayoints = display(bookinput)

    def setmessage():
      print ("Hello, please enter the number of books that you has purchased this month and we will displays the points awarded you have")

    def bookinput():
      books = 0
      books = int(input("Enter number: "))
      return books

    def display(bookinput):
      if bookinput == 0:
       print ("You have 0 point")
      elif bookinput == 1:
       print ("You have 5 points awarded")
      elif bookinput == 2:
       print ("You have 15 points awarded")
      elif bookinput == 3:
       print ("You have 30 points awarded")
      elif bookinput >= 4:
        print ("You have 60 points awarded")
      else:
       print ("Invalid number")
    book_point()

在执行时,它会显示 Traceback(最近一次调用最后一次): 文件“python”,第 29 行,在 book_point 中的文件“python”,第 6 行 文件“python”,第 25 行,显示中 TypeError: 'function' 和 'int' 的实例之间不支持 '>='

【问题讨论】:

  • 看起来 bookinput 应该是书籍。 bookinput 是一个函数,那么如何比较 bookinput >= 4?

标签: python-3.x


【解决方案1】:

没关系,我得到了答案

def book_point():
  displayoints = 0
  books = 0
  setmessage()
  books = bookinput()
  displayoints = display(books)

def setmessage():
  print ("Hello, please enter the number of books that you has purchased this month and we will displays the points awarded you have")

def bookinput():
  books = 0
  books = int(input("Enter number: "))
  return books

def display(books):
  if books == 0:
    print ("You have 0 point")
  elif books == 1:
    print ("You have 5 points awarded")
  elif books == 2:
    print ("You have 15 points awarded")
  elif books == 3:
    print ("You have 30 points awarded")
  elif books >= 4:
    print ("You have 60 points awarded")
  else:
    print ("Invalid number")
book_point()

【讨论】:

    猜你喜欢
    • 2018-09-08
    • 2021-05-17
    • 2018-04-15
    • 2020-01-11
    • 2022-12-06
    • 2017-09-01
    • 2021-08-05
    • 2019-04-07
    • 1970-01-01
    相关资源
    最近更新 更多