Sitemap
Unat

Unat

computer science @istanbul

Read

2 min readApr 15, 2020

--

readLine() her satırı 1 eleman alır

import stdio
a = []
count = 0
while not stdio.isEmpty ():
value = stdio.readLine ()

a.append(value)
count += 1
stdio.writeln("count:"+str(count))
stdio.writeln(a)
------------------------
python deneme3.py
1 2 3 4
5 6 7 8
9 10 11 12
^Z
count:3
['1 2 3 4', '5 6 7 8', '9 10 11 12']

readAll() tüm komut satırını 1 “str” eleman olarak alır.

import stdio
a = []
count = 0
while not stdio.isEmpty ():
value = stdio.readAll ()

a.append(value)
count += 1
stdio.writeln(count)
stdio.writeln(a)
------------------------
python deneme3.py
1 2 3 4 5
6 7 8 9 10
^Z
^Z
count:1
['1 2 3 4 5\n6 7 8 9 10\n']

readAllInts() tüm komut satırındaki “int” elemanları liste içine ayrı elemanlar olarak atar. str varsa kod hata verir. liste içine atıldığına dikkat etmelisin.

import stdio
a = []
count = 0
while not stdio.isEmpty ():
value = stdio.readAllInts ()
a.append(value)
count += 1
stdio.writeln("count:"+str(count))
stdio.writeln(a)
------------------------
python deneme3.py
1 2 3 4
6 7 8 9
123 2141 125 12421
^Z
^Z

count:1
[[1, 2, 3, 4, 6, 7, 8, 9, 123, 2141, 125, 12421]]

readAllInts() tüm komut satırındaki “int” elemanları liste içine ayrı elemanlar olarak atar. str varsa kod hata verir. liste içine atıldığına dikkat etmelisin.

import stdio
a = []
count = 0
while not stdio.isEmpty ():
value = stdio.readAllLines()
a.append(value)
count += 1
stdio.writeln("count:"+str(count))
stdio.writeln(a)
------------------------
python deneme3.py
seri 6 falkao 9
lemina 8 feguli 89
belhanda 10
12381249124
^Z
^Z

count:1
[['seri 6 falkao 9', 'lemina 8 feguli 89', 'belhanda 10', '12381249124']]
  1. komut satırından eleman sayısını al
  2. komut satırında alt satırda white space ile ayrılmış sayıları 1. listeye at
  3. komut satırında alt satırda white space ile ayrılmış listeleri 2. listeye at

Get Unat’s stories in your inbox

Join Medium for free to get updates from this writer.

import stdio
import sys
n =int(sys.argv[1])
a= []
b= []
while not stdio.isEmpty ():
if len(a) < n:
value = stdio.readFloat()
a.append(value)
if (len(a) == n) and (len(b) < n):
value2 = stdio.readFloat()
b.append(value2)
distance = 0
for i in range(n):
distance += (a[i] - b[i])**2
distance= distance**(1/2)
print(distance)
------------------------
python deneme3.py
-9 1 10 -1 1 #print(a) = [-9.0, 1.0, 10.0, -1.0, 1.0]
-5 9 6 7 4 #print(b) = [-5.0, 9.0, 6.0, 7.0, 4.0]
^Z
13.0
  1. komut satırından eleman sayısını al
  2. komut satırında alt satırda white space ile ayrılmış sayıları 1. listeye at. split() kullanarak her boşluk gördüğünde elemana çevirmesini sağla.
  3. komut satırında alt satırda white space ile ayrılmış listeleri 2. listeye at. split() kullanarak her boşluk gördüğünde elemana çevirmesini sağla.

readline() tek başına “-9 1 10 -1 1” olarak yani str alır. Split’le bölüp listeye at.

n =int(sys.argv[1])
a= []
b= []
while not stdio.isEmpty ():
values1 = stdio.readLine().split()
for i in values1:
a.append(i)
values2 = stdio.readLine().split()
for i in values2:
b.append(i)
print(a)
print(b)
distance = 0
for i in range(n):
distance += (int(a[i]) - int(b[i]))**2
distance= distance**(1/2)
print(distance)
------------------------
python deneme3.py
-9 1 10 -1 1 #print(a) = [-9.0, 1.0, 10.0, -1.0, 1.0]
-5 9 6 7 4 #print(b) = [-5.0, 9.0, 6.0, 7.0, 4.0]
^Z
13.0

--

--

Unat
Unat

Written by Unat

computer science @istanbul