Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 16 Online
OpenStudy (anonymous):

Hello everyone i tried writing a program that convert meter to centimeter with the conditional statement but my program did not run may be i defined it wrongly or my print command was faulty i need help once again. def meter(centimeter): """ converting meter to centimeter""" Meter = int(raw_input(" Enter number here : ") if '1 meter' == '0 centimeter': print " this is hardly possible " elif '1 meter' == '100 centimeter': print " true " elif: centimeter = (Meter * 100)/1 print " centimeter ", else: print " can't "

OpenStudy (rsmith6559):

Your if and first elif conditions both fail. The string literal "1 meter" is never going to be equivalent to "0 centimeter". You may also want to consider making Meter a float too.

OpenStudy (anonymous):

I tried using 1 meter and it still did run just like always the error message came up that my syntax is invalid.Should i concatenate '1' and 'meter' and the same on the other part of == ie '1' and 'centimeter' ?

OpenStudy (anonymous):

Because i know i can't concatenate an int with a str. how can i get this code to run if my problem is located in my if and first elif conditions ?

OpenStudy (anonymous):

i just got to understand how to use the def funtion. my code was ont defined well.

OpenStudy (anonymous):

I don't tha lang

OpenStudy (anonymous):

If you review some basic information about how variables, functions, and conditional statements work then you'll begin to understand why your code isn't working. This code will work, however: meters=int(raw_input("Please enter the number of meters you want to convert without the m:')) print "That equals this many centimeters:", meters*100

OpenStudy (anonymous):

Or, rather, it should be a double quote after the "m:"

OpenStudy (rsmith6559):

Meter -> centimeter is straightforward: cm = m * 100 # centi means 1/100 Do you need the conditional to check input? Should the program convert cm -> m too and you need to decide which way to go? There just isn't a need for conditionals for what you've described.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!