華氏から摂氏への変換

PythonPythonBeginner
今すぐ練習

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

💡 このチュートリアルは英語版からAIによって翻訳されています。原文を確認するには、 ここをクリックしてください

はじめに

多くの国では、温度を摂氏で測定します。ただし、一部の国では、温度を華氏で測定します。これら2つの測定単位の間で変換できることが重要です。このチャレンジでは、華氏を摂氏に変換する関数を書きます。


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL python(("Python")) -.-> python/BasicConceptsGroup(["Basic Concepts"]) python(("Python")) -.-> python/FunctionsGroup(["Functions"]) 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

まとめ

このチャレンジでは、華氏を摂氏に変換する関数を作成しました。これは、異なる測定単位の温度データを扱う際に必要な重要なスキルです。