华氏度到摄氏度的转换

PythonPythonBeginner
立即练习

This tutorial is from open-source community. Access the source code

💡 本教程由 AI 辅助翻译自英文原版。如需查看原文,您可以 切换至英文原版

简介

在许多国家,温度是以摄氏度为单位进行测量的。然而,在一些国家,温度是以华氏度为单位进行测量的。能够在这两种计量单位之间进行转换是很重要的。在这个挑战中,你将编写一个将华氏度转换为摄氏度的函数。


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL python(("Python")) -.-> python/FunctionsGroup(["Functions"]) python(("Python")) -.-> python/BasicConceptsGroup(["Basic Concepts"]) python/BasicConceptsGroup -.-> python/comments("Comments") python/FunctionsGroup -.-> python/function_definition("Function Definition") subgraph Lab Skills python/comments -.-> lab-13629{{"华氏度到摄氏度的转换"}} python/function_definition -.-> lab-13629{{"华氏度到摄氏度的转换"}} end

华氏度到摄氏度的转换

编写一个函数 fahrenheit_to_celsius(degrees),它接受一个华氏温度作为参数,并返回对应的摄氏温度。该函数应遵循转换公式 C = (F - 32) * 5 / 9,其中 C 是摄氏温度,F 是华氏温度。

def fahrenheit_to_celsius(degrees):
  return ((degrees - 32) * 5 / 9)
fahrenheit_to_celsius(77) ## 25.0

总结

在这个挑战中,你编写了一个将华氏度转换为摄氏度的函数。在处理不同计量单位的温度数据时,这是一项重要的技能。