Skip to content

Instantly share code, notes, and snippets.

@yosefsadek
Created January 18, 2020 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yosefsadek/aef783d947417ebb6b1abb8d314e06c3 to your computer and use it in GitHub Desktop.
Save yosefsadek/aef783d947417ebb6b1abb8d314e06c3 to your computer and use it in GitHub Desktop.
py
#function that converts miles to kilometres
def mtokm(value):
answer = value * 1.6
return answer
#function that converts kilometres to miles
def kmtom(value):
answer = value * 0.62
return answer
#function that converts cm to inches
def cmtoinch(value):
answer = value * 0.39
return answer
#function that converts inches to cm
def inchtocm(value):
answer = value * 2.54
return answer
#function that generates the menu
def menu():
print("What conversion would you like to do?")
print("1. Convert Miles to Kilometers")
print("2. Convert Kilometers to Miles")
print("3. Convert CM to Inches")
print("4. Convert Inches to CM")
menu() #calls the menu function
#gets the option from the user input
option = input(">>")
print()
#asks the user to enter the measurement
number = float(input("Enter your measurement to convert: "))
#if the option entered is 1
if option=="1":
#calls the relevant function and then displays the conversion =
print(str(number) + " miles in KM is " + str(mtokm(number)))
#if the option entered is 2
elif option=="2":
#calls the relevant function and then displays the conversion =
print(str(number) + " KM in miles is " + str(kmtom(number)))
#if the option entered is 3
elif option=="3":
#calls the relevant function and then displays the conversion =
print(str(number) + " CM in inches is " + str(cmtoinch(number)))
#if any other value is entered
else:
#calls the relevant function and then displays the conversion =
print(str(number) + " inches in CM is " + str(inchtocm(number)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment