0

beginner question about a code for converting inch(es) to cm

Hi, I have just started learning Python and am a total newbie. Besides SoloLearn I am using a book designed for beginners which came with a CD with an IDLE on it. I am already having problems with the 3rd exercise, which is to write a code for converting inch(es) to cm. inch=2.54 print("Please enter a value for inch.") xi=float(input()) xcm=xi*inch print(xi, "inch(es) equal", xcm, "cm") playground: https://code.sololearn.com/c7D39UG6OhIF The code seems to work in playground. It is also the sample solution given in the book (keep in mind, this is the very start of the book...). I had to look up the sample solution because I kept getting errors when creating own codes in the IDLE. Unfortunately, even the sample solution does not work in the IDLE: Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> xi=float(input()) ValueError: could not convert string to float: As the code works with playground, I am thinking that something is wrong with the IDLE. I hope you guys can help me.

11th May 2019, 10:44 AM
Julian
Julian - avatar
9 Antworten
+ 3
maybe you entered a number with a comma instead of a dot?
11th May 2019, 10:49 AM
Игорь Яковенко
Игорь Яковенко - avatar
+ 1
Thank you so much ~ swim ~ and Игорь Яковенко for the fast answers :) Now it all makes sense and I can continue :)
11th May 2019, 12:00 PM
Julian
Julian - avatar
0
>>> inch=2.54 >>> print("Please enter a value for inch.") Please enter a value for inch. >>> xi=float(input()) Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> xi=float(input()) ValueError: could not convert string to float: >>> This is the complete code until receiving an error message in the IDLE. To me it seems to be the exact same I entered in playground... Although playground does not have (or display) ">>>". In playground, I only had to press enter key once, in the IDLE i had to use it twice to get the next ">>>". P.S.: I do not know the different terms yet, sry.
11th May 2019, 10:59 AM
Julian
Julian - avatar
0
Oh, I see, this works. But how can I write the full code (https://code.sololearn.com/c7D39UG6OhIF) without having to enter a number? I want to be able to enter any number after it is finished. By entering a number while writing the code, it is fix, isn´t it?
11th May 2019, 11:18 AM
Julian
Julian - avatar