2014-12-03 63 views
-3

我运行此:类型错误:%d格式:需要数量,而不是元组

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 

但为什么呢?

+0

我的神啊对不起,我只是发现了现在 – pempem 2014-12-03 10:46:04

回答

2

只是一些错字在你的代码:

iq = divide = (100, 2) 

def devide (a, b): 

需要成为

iq = divide(100, 2) 

def divide (a, b): 
+0

你也应该改变鸿沟devide;) – 2014-12-03 10:35:56

+0

@VincentBeltman耶谢谢:) – 2014-12-03 10:36:47

+0

或者相反,并且改变'hight'为'height' – 2014-12-03 10:37:09

相关问题