Demo entry 6641668

HW1

   

Submitted by Csomerlot on Sep 19, 2017 at 15:35
Language: Python. Code size: 1.6 kB.

#!/usr/bin/python2.7

print """
Enter 'ft' for feet or 'm' for meters
"""

# Read in value to be converted

valueToBeConverted = raw_input('Enter value to be converted ')
##print valueToBeConverted


# Read in units its in
unitFrom = raw_input('Enter units it is in ')
##print unitFrom



# Read in units it will be converted to
unitTo = raw_input('Enter units to convert it to ')
##print unitTo


# Do the math
if unitFrom == "ft" and unitTo == 'm':
    valueConverted = float(valueToBeConverted) /3.2808
    print valueConverted, unitTo
else:
    if unitFrom == "m" and unitTo == 'ft':
        valueConverted = float(valueToBeConverted) *3.2808
        print valueConverted, unitTo
    else:
        print "Invalid unit choices"

# print value

raw_input("Hit enter to close")




print """
Enter 'ft' for feet or 'm' for meters
"""

# Read in value to be converted

valueToBeConverted = raw_input('Enter value to be converted ')
##print valueToBeConverted


# Read in units its in
unitFrom = raw_input('Enter units it is in ')
##print unitFrom



# Read in units it will be converted to
unitTo = raw_input('Enter units to convert it to ')
##print unitTo


# Do the math
if unitFrom == "ft" and unitTo == 'm':
    valueConverted = float(valueToBeConverted) /3.2808
    print valueConverted, unitTo
else:
    if unitFrom == "m" and unitTo == 'ft':
        valueConverted = float(valueToBeConverted) *3.2808
        print valueConverted, unitTo
    else:
        print "Invalid unit choices"

# print value

raw_input("Hit enter to close")

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).