I'm quite new to Python, and am trying to make a simple unit converter - was hoping if anyone could tell me where i'm going wrong?

This is the script as it stands:

input('Would you like to convert centimeters to inches (a), or inches to centimeters (b)?\ntype a or b: ')
if type('a'):
    dist_cent=float(input('measurement in centimeters: '))
    print(dist_cent /2.54)
elif type('b'):
    dist_inch=float(input('measurement in inches: '))
    print(dist_inch *2.54)

If the user inputs 'a', the first 'if' works as it should. But if the user inputs 'b', instead of running the 'elif' statement, it runs the first 'if' statement as if the user had input 'a'.

Anybody able to explain this? Would be much appreciated.
Thanks!

Thanks if you've taken an interest but have figured it out: needed to assign a variable to the function.

x=input('Would you like to:\nConvert centimeters to inches (a)\nConvert inches to centimeters (b)\n\ntype a or b: ')

if x=="a":
    dist_cent=float(input('measurement in centimeters: '))
    print(dist_cent /2.54)
elif x=="b":
    dist_inch=float(input('measurement in inches: '))
    print(dist_inch *2.54)

:)

Thanks if you've taken an interest but have figured it out: needed to assign a variable to the function.

Better formulated:
Needed to assign a variable to the function's return value.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.