マイルをキロメートルに変換する

PythonPythonBeginner
今すぐ練習

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

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

はじめに

このチャレンジでは、マイルをキロメートルに変換する Python 関数を作成します。マイル単位の距離が与えられ、それに相当するキロメートル単位の距離を返す必要があります。


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-13692{{"マイルをキロメートルに変換する"}} python/function_definition -.-> lab-13692{{"マイルをキロメートルに変換する"}} end

マイルをキロメートルに変換

miles(浮動小数点数または整数)をパラメータとして受け取り、それに相当するキロメートル単位の距離を返す Python 関数 miles_to_km を作成してください。以下の変換式を使用してください: km = mi * 1.609344

def miles_to_km(miles):
  return miles * 1.609344
miles_to_km(5.03) ## 8.09500032

まとめ

このチャレンジでは、Python 関数を使用してマイルをキロメートルに変換する方法を学びました。これで、マイル単位の任意の距離を、式 km = mi * 1.609344 を使用してキロメートルに変換できるようになりました。