【问题标题】:TypeError: %d format: a number is required, not tuple类型错误:%d 格式:需要一个数字,而不是元组
【发布时间】:2015-01-31 21:01:18
【问题描述】:

我正在运行这个:

def add (a, b):
    print "ADDING %d + %d" % (a, b)
    return a + b

def subtract (a, b):
   print "SUBSTRACTING %d - %d" %(a, b)
   return a -b

def multiply (a, b):
    print "MULTIPLYING %d * %d" % (a, b)
    return a * b

def devide (a, b):
    print "DEVIDING %d / %d" % (a, b)
    return a / b

print " lets do some math with just function!"


age = add(30, 5)
hight = subtract (78, 4)
weight = multiply (90, 2)
iq = divide = (100, 2)

print "Age: %d, Hight: %d, Weight: %d, IQ: %d" % (age, hight, weight, iq)

我明白了:

TypeError: %d format: a number is required, not tuple

但是为什么?

【问题讨论】:

  • 天哪,对不起,我现在才知道

标签: python python-2.7 typeerror


【解决方案1】:

只是代码中的一些错字:

iq = divide = (100, 2)

def devide (a, b):

需要成为

iq = divide(100, 2)

def divide (a, b):

【讨论】:

  • 你也应该将divide改为devide ;)
  • 或者反过来,把hight也改成height
猜你喜欢
  • 2020-09-24
  • 2015-02-04
  • 2015-12-20
  • 1970-01-01
  • 1970-01-01
  • 2017-12-28
  • 2021-07-08
  • 2017-11-17
  • 1970-01-01
相关资源
最近更新 更多