+ 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 Answers
+ 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