Created
January 18, 2020 00:24
-
-
Save yosefsadek/aef783d947417ebb6b1abb8d314e06c3 to your computer and use it in GitHub Desktop.
py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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