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 "
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.
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' ?
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 ?
i just got to understand how to use the def funtion. my code was ont defined well.
I don't tha lang
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
Or, rather, it should be a double quote after the "m:"
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.
Join our real-time social learning platform and learn together with your friends!