def FractionDivider(a,b,c,d):
'''
Divides a fraction by another fraction...
'''
n = a #setting each individual parameter to a new name.
d = b #creating a pointer is often useful in order to preserve original data
n2 = c #but it is however not necessary in this function
d2 = d
return (float(n)/d) / (float(n2)/d2) #we return our math, Also order of operations exists here '''1/2/3/4 != (1/2)/(3/4)'''
print FractionDivider(1, 2, 3, 4) #here we print the result of our function call.
#indentation is extremely important in Python
They are two examples of sequence data types (see Sequence Types —
list, tuple, range). Since Python is an evolving language, other
sequence data types may be added. There is also another standard
sequence data type: the tuple.
所以在函数中,如果你想给变量赋值,那么就把它作为参数传递
例如:
def FractionDivider(a,b,c,d):
n = a
d = b
n2 = c
d2 = d
n=()
是一个有效的python语句,没有任何问题。但是n=()
正在将n
求值为空tuple()
。我相信你想做的事情如下。你知道吗这里有一个简单的方法来编写相同的函数
您的函数正在接受参数
a
、b
、c
和d
,但是您没有在任何地方使用它们。而是定义了四个新变量。尝试:去掉你的空括号,看看这是否符合你的意图。你知道吗
不能在执行n=()时声明变量,然后尝试为其分配整数或字符串。你知道吗
n=()并不意味着:
()->;元组https://docs.python.org/3/tutorial/datastructures.html
所以在函数中,如果你想给变量赋值,那么就把它作为参数传递
例如:
考虑从上面的链接阅读更多关于元组的内容
相关问题 更多 >
编程相关推荐