|
|
вернуться в форумPython3 help me to understand, what is wrong? 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? Re: Python3 help me to understand, what is wrong? 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? 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? 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? 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 != ''] |
|
|