r/programminghelp • • Oct 07 '21

Python Need assistance writing code that converts cm into mm, inches, or feet

Hello,

This is my first post here, so apologies if this post isn't rule friendly.

My assignment for Computer Science is to write a program that converts cm into mm, inches, or feet based on the users choice. We're required to use if statements.

I'm very new to this, so I apologize if my coding is amateurish.

Here is what I have so far:

 cm=float(input("How many cm do you want to convert?"))
choice=input("Choose (m)m, (i)nches, (f)eet:")
if choice=='m' :
    print(cm*10)

When I run the program, it accepts the inputs, but doesn't print cm*10. What am I doing wrong?

4 Upvotes

3 comments sorted by

1

u/[deleted] Oct 07 '21

As long as the user is choosing mm by pressing "m", the code seems to work fine. You haven't given code for the other options (inches and feet). What steps are you taking that it doesn't print anything?

1

u/JacksonG Oct 07 '21

I tried adding other if statements for inches and feet.

cm=int(input("How many cm do you want to convert?"))
choice=input("Choose (m)m, (i)nches, (f)eet:") if choice == 'm' : print(cm10) if choice == 'i': print(cm0.3937) if choice =='f': print(cm*0.0328)

Same thing happens. I input the the amount of cm's, I input the measurement, and the answer doesn't print.

Here is the result I get:

How many cm do you want to convert? 10
Choose (m)m, (i)nches, (f)eet: i
In [104]:

I am so stuck. Thank you for the reply.

1

u/[deleted] Oct 07 '21

Other than the fact you should be using if, elif, else, that sounds fine. Please edit your original post and include a pastebin link to ALL of your code, per Rule #2, and I'll take a look.