这段代码在Python中的语法错误是什么?

问题描述:

我是编程和python的新手,我正在看一个演讲,我想创建一个简单的功能,如讲师在视频中做的,所以我设计了3个功能,另外,意思是,意味着如下所示添加只加2个数字和平均函数计算两个数字的均值mean_Addition加上平均值和两个数字的加法这段代码在Python中的语法错误是什么?

我编写了代码并运行程序,但它告诉我有一些语法错误,我检查了一遍又一遍,但我不能决定什么是我的简单程序的错误

代码:

def addition(float1,float2): 
    '''(float,float)-> float 

return the addition of float1 and float2 . 

>>> addition(2,3) 
5.0 
>>>addition(4,6) 
10.0 ''' 
    return float1+float2 


def mean(x , y): 
    ''' 
(number,number)-> float 
return the mean of two numbers , x and y . 
>>> mean(2,4) 
3.0 
>>> mean(9,2) 
5.5 
''' 
    return addition(x,y)/ 2 



def Mean_Addition(t,s): 
''' 
(float,float)->float 
return the mean of the two numbers plus the addition of the two numbers 
>>> Mean_Addition(1,2) 
4.5 
>>> Mean_Addition(4,5) 
13.5 
''' 
    return addition(t,s) + mean(t,s) 

我想提到的一件事是,错误是在第三个函数Mean_Addition,因为当我删除这部分它工作得很好!

的问题是,当我选择运行模它说:“预期的缩进块”

究竟什么是我所做出的语法错误?

谢谢。


注:对于那些谁就会在未来的探讨这个问题,这是我做(我了解到这起答案)语法错误是我写

def Mean_Addition(t,s): 
''' 
(float,float)->float 

,但我们不应该把“‘’””下的‘高清’,我们应该让‘高清’ 所以正确的代码是

def Mean_Addition(t,s): 
    ''' 
(float,float)->float 
+5

下方空间的文档字符串是不是我缩进 – Volatility 2013-04-05 23:15:15

+2

,你有一个额外的“最后 – tacaswell 2013-04-05 23:16:14

+0

而你没有告诉我们从你的错误的完整追溯。 – abarnert 2013-04-05 23:31:32

def addition(float1,float2): 
    '''(float,float)-> float 

return the addition of float1 and float2 . 

>>> addition(2,3) 
5.0 
>>>addition(4,6) 
10.0 ''' 
    return float1+float2 


def mean(x , y): 
    ''' 
(number,number)-> float 
return the mean of two numbers , x and y . 
>>> mean(2,4) 
3.0 
>>> mean(9,2) 
5.5 
''' 
    return addition(x,y)/ 2 



def Mean_Addition(t,s): 
    ''' <----- the error was here 
(float,float)->float 
return the mean of the two numbers plus the addition of the two numbers 
>>> Mean_Addition(1,2) 
4.5 
>>> Mean_Addition(4,5) 
13.5 
''' 
    return addition(t,s) + mean(t,s) 
+1

哪里出错?什么是有错误的短语? – 2013-04-05 23:40:41

+1

记得在python缩进中有意义。仔细比较标记的行。 – tacaswell 2013-04-05 23:41:59

+0

谢谢你的帮助,先生:)) – 2013-04-06 00:28:45