python "Function call with parameter: Converting measurements?"

标签 python python-3.x function-calls

<分区>

我正在参加我的第一门编程类(class),如果这是一个愚蠢的问题/可能在本网站上分类错误,我深表歉意。我正在研究的练习题之一如下:

定义一个函数 print_total_inches,参数为 num_feet 和 num_inches,打印总英寸数。注意:一英尺有 12 英寸。例如:
print_total_inches(5, 8) 打印:
总英寸:68

所附照片是我执行的代码以及我收到的错误。非常感谢任何帮助/资源。谢谢!

My code so far

最佳答案

您的代码无法格式化输入(以及缺少所需的计算)。

def print_total_inches (num_feet, num_inches):
    print('Total inches:', num_feet * 12 + num_inches)

print_total_inches(5, 8)

def total_inches (num_feet, num_inches):
    return num_feet * 12 + num_inches

print('Total inches:', total_inches(5, 8))

应该做 - 当没有什么可返回时不需要 return

关于 python "Function call with parameter: Converting measurements?",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44990497/

相关文章:

c++ - c/c++ | int * 除外,给定 int (返回指针??)

python - 根据登录用户过滤 Django 管理控制台行

python - 如何使用多处理将多个 Excel 工作表导入 Pandas ?

python - 如何使用python SDK删除Minio存储中的路径?

python - 如何在循环中的值之间打印空格?

c++ - 函数的前向声明搞砸了,说 args 是未声明的标识符

python - 正则表达式中的嵌套文本

python-3.x - ElementNotVisibleException : Message: element not interactable error while trying to click on the top video in a youtube search

python-3.x - Python 3 的进程之间共享多维数组

c# - 如何从 VBScript 调用 C# DLL 函数