ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1001. Reverse Root

Python3 help me to understand, what is wrong?
Posted by master8282 20 Jul 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?
Posted by Mahilewets 20 Jul 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?
Posted by Mahilewets 20 Jul 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?
Posted by Mahilewets 20 Jul 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?
Posted by Mahilewets 20 Jul 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?
Posted by master8282 20 Jul 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 != '']