Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis+ 1
Error converting input string. What is wrong here?
ŠŠ¾Š»ŃŠ·Š¾Š²Š°ŃŠµŠ»Ń Š²Š²Š¾Š“ŠøŃ ŃŠøŃŠ»Š¾, Š½ŠµŠ¾Š±Ń Š¾Š“ŠøŠ¼Š¾ Š²ŃŃŃŠøŃŠ°ŃŃ ŠŗŠ¾ŃŠµŠ½Ń ŃŃŠ¾Š³Š¾ ŃŠøŃŠ»Š°. ŠŠ°Šŗ ŠøŃŠæŃŠ°Š²ŠøŃŃ ŠŗŠ¾Š“? The user enters a number, need to convert number to sqrt. How to fix the code? num = float(input()) import math num2 = math.sqrt(num) ŠŃŠ“Š°ŠµŃ, ŃŃŠ¾ Š½ŠµŃŠ“Š°Š»Š¾ŃŃ ŠæŃŠµŠ¾Š±ŃŠ°Š·Š¾Š²Š°ŃŃ ŃŃŃŠ¾ŠŗŃ Š² ŃŠøŃŠ»Š¾ Ń ŠæŠ»Š°Š²Š°ŃŃŠµŠ¹ ŃŠ¾ŃŠŗŠ¾Š¹ (Š ŠæŠµŃŠ¾ŃŠ½ŠøŃŠµ Š²ŃŠ¾Š“Šµ Š±Ń ŃŠ°Š±Š¾ŃŠ°ŠµŃ, Š° Š½Š° ŠŗŠ¾Š¼ŠæŃŃŃŠµŃŠµ ŃŃŠ°Š·Ń Š²ŃŠ“Š°ŠµŃ ŃŃŃ Š¾ŃŠøŠ±ŠŗŃ) ValueError: could not convert string to float: 'num2 = math.sqrt(num)'
9 Respostas
+ 5
hi, i took the code as it is from you, and it could run. Not running properly, but without Error message. the cod as povided by you is running in an infinite loop, as num2 is a float after calculating math.sqrt(num). so the result of modulo division if num2 % 10 == 0 will never evaluate True. and so the program can not terminate.
but anyway, there must be a difference between the code that causes an error for you, and the code that is presented here. i have put it now with my suggestions together in a file, so that you can run it in playground. i have inserted an additional print statement,just to visualize what happens.
https://code.sololearn.com/cCd2MMp9Sxyv/?ref=app
+ 5
hi, i think that the problem is, that this line of code : num2 = math.sqrt(num) (in else clause) always is producing a float, that never will match the if clause for break. so changing code to this, will solve the problem: num2 = int(math.sqrt(num)).
+ 2
There's no problem with thw code.
Probably user haven't entered a valid number
+ 2
Are you sure?
The code works for me properly.
+ 1
No, the number's normal. Python displays an error immediately when the code runs.
+ 1
The next time the program was checked, an error occurred (the code did not change):
(1 line) SyntaxError: myltiple statments found while compiling a single statments
This's obtained on the computer. In the "ŠæŠµŃŠ¾ŃŠ½ŠøŃŠ°" (sandbox), it doesn't start at all
The code:
https://code.sololearn.com/c7L1i8EbiFv2/?ref=app
+ 1
This has not changed anything. The error still appears:
(1 line) SyntaxError: multiple statements found while compiling a single statements
+ 1
Thank you. The problem was with the python compiler on my computer
+ 1
During the written code, I accidentally wrote 10 instead of 1, so endless code came out