Demo entry 2426689

Testing python to HTML

   

Submitted by anonymous on Aug 20, 2015 at 12:46
Language: Python 3. Code size: 631 Bytes.

'''
Unit conversion: Between KM to Miles
'''

def print_menu():
    print ('1. Kilometers to Miles')
    print ('2. Miles to Kilometers')

def km_miles():
    km = float(input('Enter a distance in kilometers: '))
    miles = km / 1.609

    print ('Distance in miles: {0}'.format(miles))

def miles_km():
    miles = float(input('Enter a distance in miles: '))
    km = miles * 1.609

    print ('Distance in kilometers: {0}'.format(km))

if __name__ == '__main__':
    print_menu()
    choice = int(input('Which conversion would you like to do?: '))
    if choice == 1:
        km_miles()

    if choice == 2:
        miles_km()

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).