Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
艰苦学习python练习21帮助_Python - Fatal编程技术网

艰苦学习python练习21帮助

艰苦学习python练习21帮助,python,Python,嘿,伙计们,我花了一些时间在这一点上,但我发现它真的很难,无法理解。这本书是这么说的: 剧本的结尾是一个谜。 我取一的返回值 函数,并将其用作参数 另一个功能。我是在做这件事 一条链,这样我就可以创造一个 使用函数的公式。看起来 真的很奇怪,但是如果你 脚本可以看到结果。什么 你应该做的就是试着找出答案 正常的公式可以重新创建 这是一组相同的操作 谢谢 #functions can return something too def add(a, b): print 'ADDING %d

嘿,伙计们,我花了一些时间在这一点上,但我发现它真的很难,无法理解。这本书是这么说的:

剧本的结尾是一个谜。 我取一的返回值 函数,并将其用作参数 另一个功能。我是在做这件事 一条链,这样我就可以创造一个 使用函数的公式。看起来 真的很奇怪,但是如果你 脚本可以看到结果。什么 你应该做的就是试着找出答案 正常的公式可以重新创建 这是一组相同的操作

谢谢

#functions can return something too
def add(a, b):
    print 'ADDING %d + %d' % (a, b)
    return a + b

def subtract(a, b):
    print 'SUBTRACTING %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

age = add(15, 5)
height = subtract(18, 3)
weight = multiply(100, 3)
iq = devide(100, 20)

print 'age: %d, height: %d, weight: %d, iq: %d' % (age, height, weight, iq)

#puzzle for extra credit
what = add(age, subtract(height, multiply(weight, devide(iq, 2))))
print "That becomes: ", what, "Can you do it by hand?"

您只需通过将函数体(非打印语句)替换为最终函数调用来逐步完成此过程。我先给你介绍一下:

加(年龄,减去(身高,乘以(体重,除以(智商,2)))

变成:

age + subtract(height, multiply(weight, devide(iq, 2)))
“正常”公式应为:

what = (15+5) + (18-3) - (100*3)*(100/20)/2

问题到底是什么?额外的积分是年龄+(身高-体重*iq/2)…即年龄=10,身高=15,体重=300,iq=5,什么=-725..这很奇怪,我几乎总是从里到外(即,我要做的第一件事是用
(iq/2)
替换
设备(iq,2)
)。“我以为每个人都这么做了。”丹尼尔·迪保洛:没错。这是大多数语言(包括Python)计算此类语句的方式。哈斯克尔就是个很好的例子……呵呵,我真的没怎么想。为了清晰起见,我只是从左向右走了一圈。嗯,手工计算代码时,这没什么大不了的;)
above question you can only call the function. There is no arithmetic can't be performed at time of final function call. Because at final call if you try to add some arithmetic sign there will be show error like:

"**TypeError: unsupported operand type(s) for +: 'int' and 'tuple'"is question.**

There is shown little form of this question**

from sys import argv
#script=argv def add(a,b):
    print "Addition %d+%d" %(a,b)
    return a+b a=add(34,43) print "add=a %d" %(a) def sub(a,b):
    print "Addition %d-%d" %(a,b)
    return a-b b=sub(234,123) print "sub=a %d" %(b)

d=12 print "New experiment" c=add(a,sub(b,add(a,add(a,b)))) print "Final C=%d" %(c)