ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1001. Обратный корень

Python3 help me to understand, what is wrong?
Послано master8282 20 июл 2017 03:12
Original code in your page:

string = input()
split_input = string.split()
lst = []
[lst.append(int(ndx) ** 0.5) for ndx in split_input]
[print("%.4f" % round(ndx, 4)) for ndx in lst[::-1]]

My tests in spyder:

Code:

with open('/tmp/123.txt', 'r') as f:
    string = f.read()

split_input = string.split()
lst = []
[lst.append(int(ndx) ** 0.5) for ndx in split_input]
[print("%.4f" % round(ndx, 4)) for ndx in lst[::-1]]

Answer:

runfile('/home/ant/.config/spyder-py3/temp.py', wdir='/home/ant/.config/spyder-py3')
2297.0716
936297014.1164
0.0000
37.7757

Edited by author 20.07.2017 03:14

Edited by author 20.07.2017 03:15
Re: Python3 help me to understand, what is wrong?
Послано Mahilewets 20 июл 2017 08:28
http://ideone.com/nR7MOy

Your code also don't work in ideone.com
Re: Python3 help me to understand, what is wrong?
Послано Mahilewets 20 июл 2017 08:32
What does input() ?
I think input just reads a LINE
Not  SEVERAL LINES
input()  just reads ONE LINE
Re: Python3 help me to understand, what is wrong?
Послано Mahilewets 20 июл 2017 08:34
There are multiple lines in the input data
That is written in the statement
You are reading just the first line
And you are missing numbers on the next lines
Re: Python3 help me to understand, what is wrong?
Послано Mahilewets 20 июл 2017 08:37
I suggest you to use
for line in stdin :
    for x in line. split () :
        ans. append (int(x) **0.5)
Re: Python3 help me to understand, what is wrong?
Послано master8282 20 июл 2017 23:22
Thank you, gotcha you.

Now the code passed well.

import sys
import re

lst = []
for ndx in sys.stdin:
    lst += re.findall(r'\d+|$', ndx)
[print("%.4f" % round(int(ndx)**0.5, 4)) for ndx in lst[::-1] if ndx != '']