here is what I have so far. it works and converts, but it asks the user to enter a number in twice. Is this because in my conversion function I am recalling the distance function that asks for the input?
I'm not sure if it is my understanding of functions thats lacking or what, hoping you guys can point me in the right direction.
def distance():
distMeters =float(input('enter the distance in meters'))
if distMeters <= 0:
print ('that is an invalid distance, please enter another')
return distMeters
def kilometers():
km = distance() * 0.001
print('your distance conversion in kilometers is ' + str(km) + ' km')
def inches():
inch = distance() * 39.37
print (inch)
def feet():
ft = distance() * 3.281
print (ft)
def menu():
print ('choose which units you would like to convert to from the menu')
print ()
print ('1. Convert to kilometers')
print ('2. Convert to inches')
print ('3. Convert to feet')
print ('4. Exit the program')
def conversions():
loop =1
while loop ==1:
choice = int(input('what menu option do you choose? '))
print ()
if choice >= 5:
print ('that is not a choice in the listing. Try Again.')
if choice == 1:
print ('you chose to convert meters to kilometers')
kilometers()
if choice == 2:
print ('you chose to convert meters to inches')
inches()
if choice == 3:
print ('you chose to convert meters to feet')
feet()
if choice == 4:
print ('Thank you for using the converter, program is now quitting')
break
conversions()
menu()

New Topic/Question
Reply




MultiQuote





|