i finally got my meter to centimeter program right and it runs fine but it has its limits it can convert from 100m upward to cm why? please you all should take a look meter = float(raw_input("Enter number here: ")) meter2 = 1 centimeter = 100 if meter2 > centimeter: print "this operation can't be carry out" elif meter2 == centimeter: print "1 meter is equivalent to 100 centimeter" elif meter < centimeter: centimeter2 = (meter*centimeter)/meter2 print "centimeter2:",centimeter2 else: print "carry out nothing"
rsmith6559 i know you said to convert m to cm is straight forward i just thought i try and see if i can use the condition statement to write a program that converts m to cm.Liking test myself if i really understand how the condition statement and variables works.
@rsmith6559 i also followed your advice and did the conversion in a straight forward way and its perfect m = float(raw_input("Enter number here:")) cm = m*100 print " cm ",cm but i still wanna know how to make this code meter = float(raw_input("Enter number here: ")) meter2 = 1 centimeter = 100 if meter2 > centimeter: print "this operation can't be carry out" elif meter2 == centimeter: print "1 meter is equivalent to 100 centimeter" elif meter < centimeter: centimeter2 = (meter*centimeter)/meter2 print "centimeter2:",centimeter2 else: print "carry out nothing" convert without having limits
You would have to convert meter2 to centimeters. You're doing comparisons when the numbers are in different units.
Hi guys i finally found the bug in my program now it works perfectly thank you @rsmith6559 contribution helped me alot #conversion from meter to centimeter meter = float(raw_input("Enter number here: ")) meter2 = 1 centimeter = 100 if meter2 > centimeter: print "this operation can't be carry out" elif meter2 == centimeter: print "1 meter is equivalent to 100 centimeter" elif meter2 <= centimeter: centimeter2 = (meter*centimeter)/meter2 print "centimeter2:",centimeter2 else: print "carry out nothing"
There are some things I really don't get in your program: `meter2` and `centimeter` are constants, right ? Since they're never reassigned, you will always have `meter2 < centimeter`. So you will always end in your third case. Maybe I'm wrong but I think all the other stuff is useless. Here is a much simpler version, appropriate to the difficulty of the problem: ``` #conversion from meter to centimeter meter = float(raw_input("Enter number here: ")) centimeter = meter * 100 print "centimeter:",centimeter
Join our real-time social learning platform and learn together with your friends!