Skip to content

Instantly share code, notes, and snippets.

@oiojin831
Created August 4, 2021 00:26
Show Gist options
  • Save oiojin831/15868a09b6076f536c64e2c8e15faec4 to your computer and use it in GitHub Desktop.
Save oiojin831/15868a09b6076f536c64e2c8e15faec4 to your computer and use it in GitHub Desktop.
def cm_to_inch(cm):
return cm / 2.54
def inch_to_cm(inch):
return inch * 2.54
def unit_converter(num, unit):
if unit == "inch":
new_cm = inch_to_cm(num)
return f"{new_cm} cm"
elif unit == "cm":
new_inch = cm_to_inch(num)
return f"{new_inch} inch"
print(unit_converter(10, "inch"))
print(unit_converter(25.4, "cm"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment