为什么在1号线之后终止?

2024-03-28 15:15:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着做程序设计课程的介绍,基本上只是重打课堂上的例子,以确保我理解的东西。你知道吗

通常情况下,这很好地解决了问题,但现在我遇到了一些代码,由于某种原因,这些代码在第1行之后终止,我不想这样做。你知道吗

def convert_to_celsius(fahrenheit):
    '''(number) --> number
Return the number of Celsius degrees equivalent to fahrenheit degrees.

>>>convert_to_celsius(32)
0
>>>convert_to_celsius(212)
100
'''
    return (fahrenheit - 32) * 5 / 9

这是哪里坏的?如何修复它使其正常运行?你知道吗


Tags: theto代码numberconvertreturndef情况
1条回答
网友
1楼 · 发布于 2024-03-28 15:15:03

我有点不确定你的问题是什么,但我猜你在定义一个函数,但从来没有调用它。为了调用函数,需要使用函数名并提供参数。e、 g.:

#This next block defines the function
def convert_to_celsius(fahrenheit):
    return (fahrenheit - 32) * 5 / 9

#call/use the function
result = convert_to_celsius(100)
#print the results
print(result)

相关问题 更多 >