Python函数代码错误 [英] Python Function Code Error

查看:104
本文介绍了Python函数代码错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个给出f(x)的代码。显然,我的工作不正常。你可以帮忙吗?

$ $ $ $ $ $ $ $ $ $ $'$'$' b返回-5(n ** 5)+69.0(n ** 2)-47


print f(2)

谢谢!

解决方案

使用这个:

  return(-5 *(n ** 5))+(69.0 *(n ** 2)) -  47 

您正在使用的代数符号即省略'*' sign导致python认为你正在尝试进行函数调用:

pre $ 69.0(n ** 2)#python认为是69.0是一个函数名,n ** 2是这个调用的参数

这就是为什么'*'操作符在两个操作数之间是必需的。


I am trying to build a code that spits out y given f(x). Apparently, mine isn't working. Can you please help?

def f(n):
    '''The Function'''
    return -5(n**5)+69.0(n**2)-47


print f(2)

Thank you!

解决方案

Use this:

return (-5*(n**5))+(69.0*(n**2))-47

The algebraic notation you are using i.e. omitting the '*' sign causes python to think that you are trying to make a function call:

69.0(n**2)  # python thinks 69.0 is a function name and n**2 is the parameter of this call

That is why the '*' operator is necessary, between two operands.

这篇关于Python函数代码错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆