forked from tdwojak/Python2017
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
a0fecba5c4 | |||
26afa652a5 | |||
f61d161938 | |||
5d25e165c4 | |||
dc5fb3f34b | |||
fd67d4b96f | |||
1599eb71ba | |||
524eefe436 | |||
7ef244fb88 | |||
d8025c91ff | |||
378fee7582 |
@ -1,24 +1,38 @@
|
|||||||
ID | labs02:task07 | labs02:task08 | labs02:task09 | labs02:task10 | labs02:task11
|
ID | labs02:task07 | labs02:task08 | labs02:task09 | labs02:task10 | labs02:task11 | labs03 | labs04 | labs06 | Punkty | Ocena |
|
||||||
---------|-----------------|-----------------|-----------------|-----------------|---------------
|
---------|-----------------|-----------------|-----------------|-----------------|-----------------|----------|----------|----------|--------|-------|
|
||||||
s45168 | 0 | 0 | 0 | 0 | 0
|
s45146 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||||
s45162 | 1 | 1 | 1 | 1 | 1
|
s45147 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||||
s45158 | 1 | 1 | 0 | 0 | 1
|
s45148 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||||
szwedek | 1 | 1 | 1 | 1 | 1
|
s45150 | 1 | 1 | 1 | 1 | 1 | 2 | 1 | 8 | 16 | 4 |
|
||||||
s45155 | 1 | 1 | 1 | 1 | 1
|
s45151 | 1 | 1 | 1 | 1 | 1 | 0 | 5 | 8 | 18 | 4.5 |
|
||||||
s45152 | 1 | 1 | 1 | 0 | 1
|
s45152 | 1 | 1 | 1 | 0 | 1 | 0 | 5 | 8 | 17 | 4 |
|
||||||
s45148 | 1 | 1 | 1 | 1 | 1
|
s45153 | 0 | 1 | 1 | 1 | 1 | 4 | 0 | 8 | 16 | 4 |
|
||||||
s45166 | 1 | 1 | 1 | 1 | 1
|
s45155 | 1 | 1 | 1 | 1 | 1 | 1 | 5 | 8 | 19 | 4.5 |
|
||||||
s45151 | 1 | 1 | 1 | 1 | 1
|
s45156 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||||
s45146 | 1 | 1 | 1 | 1 | 1
|
s45157 | 1 | 1 | 1 | 1 | 1 | 4 | 4 | 8 | 21 | 5 |
|
||||||
s45150 | 1 | 1 | 1 | 1 | 1
|
s45158 | 1 | 1 | 0 | 0 | 1 | 4 | 5 | 8 | 19 | 4.5 |
|
||||||
s45452 | 1 | 1 | 1 | 1 | 1
|
s45159 | 1 | 1 | 1 | 1 | 1 | 2 | 3 | 8 | 18 | 4.5 |
|
||||||
s45165 | 1 | 1 | 1 | 1 | 1
|
s45160 | 1 | 1 | 1 | 1 | 1 | 4 | 4 | 8 | 21 | 5 |
|
||||||
s45160 | 1 | 1 | 1 | 1 | 1
|
s45161 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||||
s45153 | 0 | 0 | 0 | 0 | 0
|
s45162 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||||
s45156 | 1 | 1 | 1 | 1 | 1
|
s45163 | 1 | 1 | 1 | 1 | 1 | 4 | 4 | 8 | 21 | 5 |
|
||||||
s45157 | 0 | 0 | 1 | 1 | 1
|
s45164 | 1 | 1 | 0 | 1 | 0 | 0 | 5 | 8 | 16 | 4 |
|
||||||
s45167 | 1 | 1 | 1 | 1 | 1
|
s45165 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||||
s45147 | 1 | 0 | 0 | 1 | 0
|
s45166 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||||
s45159 | 0 | 0 | 0 | 0 | 0
|
s45167 | 1 | 1 | 1 | 1 | 1 | 0 | 5 | 8 | 17 | 4 |
|
||||||
s45161 | 1 | 1 | 1 | 1 | 1
|
s45168 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 |
|
||||||
s45164 | 1 | 1 | 0 | 1 | 0
|
s45452 | 1 | 1 | 1 | 1 | 1 | 4 | 4 | 8 | 21 | 5 |
|
||||||
|
szwedek | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 10 | 24 | 5 |
|
||||||
|
|
||||||
|
Skala:
|
||||||
|
|
||||||
|
Punkty | Ocena |
|
||||||
|
-------|-------|
|
||||||
|
24-20 | 5 |
|
||||||
|
19-18 | 4.5 |
|
||||||
|
17-16 | 4 |
|
||||||
|
15-13 | 3 |
|
||||||
|
12-0 | 2 |
|
||||||
|
|
||||||
|
|
||||||
|
Max: 22
|
||||||
|
@ -7,7 +7,7 @@ która zawiera tylko elementy z list o parzystych indeksach.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def even_elements(lista):
|
def even_elements(lista):
|
||||||
return lista[::2]
|
pass
|
||||||
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
|
@ -5,15 +5,8 @@
|
|||||||
Napisz funkcję days_in_year zwracającą liczbę dni w roku (365 albo 366).
|
Napisz funkcję days_in_year zwracającą liczbę dni w roku (365 albo 366).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def days_in_year(year):
|
def days_in_year(days):
|
||||||
if year % 4 == 0 and year % 100 == 0 and year % 400 == 0:
|
pass
|
||||||
return 366
|
|
||||||
elif year % 4 == 0 and year % 100 != 0:
|
|
||||||
return 366
|
|
||||||
elif year % 4 == 0 and year % 100 == 0 and year % 400 != 0:
|
|
||||||
return 365
|
|
||||||
else:
|
|
||||||
return 365
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [[2015], [2012], [1900], [2400], [1977]]
|
inputs = [[2015], [2012], [1900], [2400], [1977]]
|
||||||
|
@ -13,11 +13,7 @@ jak 'set', która przechowuje elementy bez powtórzeń.)
|
|||||||
|
|
||||||
|
|
||||||
def oov(text, vocab):
|
def oov(text, vocab):
|
||||||
s=set()
|
pass
|
||||||
for i in text.split():
|
|
||||||
if i not in vocab:
|
|
||||||
s.add(i)
|
|
||||||
return s
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,14 +7,7 @@ Jeśli podany argument jest mniejszy od 1 powinna być zwracana wartość 0.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def sum_from_one_to_n(n):
|
def sum_from_one_to_n(n):
|
||||||
if n<1:
|
pass
|
||||||
return 0
|
|
||||||
else:
|
|
||||||
x=0
|
|
||||||
for i in range (n+1):
|
|
||||||
x=x+i
|
|
||||||
return x
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
|
@ -9,11 +9,8 @@ trzyelementowe listy liczb zmiennoprzecinkowych.
|
|||||||
np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5.
|
np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def euclidean_distance(x, y):
|
def euclidean_distance(x, y):
|
||||||
dist=((x[0]-y[0])**2+(x[1]-y[1])**2+(x[2]-y[2])**2)**(1/2)
|
pass
|
||||||
return dist
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [[(2.3, 4.3, -7.5), (2.3, 8.5, -7.5)]]
|
inputs = [[(2.3, 4.3, -7.5), (2.3, 8.5, -7.5)]]
|
||||||
|
@ -10,14 +10,7 @@ ma być zwracany napis "It's not a Big 'No!'".
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def big_no(n):
|
def big_no(n):
|
||||||
if n<5:
|
pass
|
||||||
return("It's not a Big 'No!'")
|
|
||||||
else:
|
|
||||||
tekst="N"
|
|
||||||
for i in range (n):
|
|
||||||
tekst += "O"
|
|
||||||
tekst += "!"
|
|
||||||
return(tekst)
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [[5], [6], [2]]
|
inputs = [[5], [6], [2]]
|
||||||
|
@ -6,10 +6,7 @@ Napisz funkcję char_sum, która dla zadanego łańcucha zwraca
|
|||||||
sumę kodów ASCII znaków.
|
sumę kodów ASCII znaków.
|
||||||
"""
|
"""
|
||||||
def char_sum(text):
|
def char_sum(text):
|
||||||
suma=0
|
pass
|
||||||
for i in range (len(text)):
|
|
||||||
suma+=ord(text[i])
|
|
||||||
return(suma)
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [["this is a string"], ["this is another string"]]
|
inputs = [["this is a string"], ["this is another string"]]
|
||||||
|
@ -7,12 +7,7 @@ przez 3 lub 5 mniejszych niż n.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def sum_div35(n):
|
def sum_div35(n):
|
||||||
suma=0
|
pass
|
||||||
for i in range(n):
|
|
||||||
if i%3==0 or i%5==0:
|
|
||||||
suma+=i
|
|
||||||
return(suma)
|
|
||||||
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [[10], [100], [3845]]
|
inputs = [[10], [100], [3845]]
|
||||||
|
@ -9,7 +9,7 @@ Np. leet('leet') powinno zwrócić '1337'.
|
|||||||
|
|
||||||
|
|
||||||
def leet_speak(text):
|
def leet_speak(text):
|
||||||
return(text.replace("e","3").replace("l", "1").replace("o", "0").replace("t", "7"))
|
pass
|
||||||
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
|
@ -9,14 +9,7 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
|
|||||||
|
|
||||||
|
|
||||||
def pokemon_speak(text):
|
def pokemon_speak(text):
|
||||||
for i in range(len(text)):
|
pass
|
||||||
if i == 0:
|
|
||||||
mytext=''.join(['', text[i].upper()])
|
|
||||||
elif i % 2 == 0:
|
|
||||||
mytext = ''.join([mytext[:i], text[i].upper()])
|
|
||||||
else:
|
|
||||||
mytext = ''.join([mytext[:i], text[i]])
|
|
||||||
return (mytext)
|
|
||||||
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
|
@ -9,14 +9,7 @@ Oba napisy będą składać się wyłacznie z małych liter.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def common_chars(string1, string2):
|
def common_chars(string1, string2):
|
||||||
s=[]
|
pass
|
||||||
s1 = list(set(string1.replace(' ','')))
|
|
||||||
s2 = list(set(string2.replace(' ','')))
|
|
||||||
for i in s1:
|
|
||||||
if i in s2:
|
|
||||||
s.append(i)
|
|
||||||
s.sort()
|
|
||||||
return s
|
|
||||||
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.66, 49.6/22.6/12.3/7.0 (BP=1.000, ratio=1.019, hyp_len=43697, ref_len=42903)
|
@ -1,8 +0,0 @@
|
|||||||
lista=[1,2,3,4,5,23,4,1,2,3]
|
|
||||||
print (id(lista))
|
|
||||||
|
|
||||||
napis='Hello'
|
|
||||||
print (id(napis))
|
|
||||||
|
|
||||||
zmiennoprzecinkowa=12.233
|
|
||||||
print (id(zmiennoprzecinkowa))
|
|
@ -1,16 +0,0 @@
|
|||||||
import glob
|
|
||||||
import re
|
|
||||||
files=glob.glob("scores\*.*")
|
|
||||||
c=[]
|
|
||||||
for file in files:
|
|
||||||
with open(file, 'r') as current_file:
|
|
||||||
a=current_file.read(12)
|
|
||||||
a=a[7:12]
|
|
||||||
a = [float(i) for i in re.findall(r"[-+]?\d*\.\d*", a)]
|
|
||||||
c.append(a)
|
|
||||||
c[0]
|
|
||||||
w=c.index(max(c))
|
|
||||||
myfile=files[w]
|
|
||||||
import os
|
|
||||||
print (os.getcwd()+"\\"+ myfile)
|
|
||||||
|
|
@ -309,13 +309,13 @@
|
|||||||
{
|
{
|
||||||
"ename": "AttributeError",
|
"ename": "AttributeError",
|
||||||
"evalue": "'Parser' object has no attribute '__parse'",
|
"evalue": "'Parser' object has no attribute '__parse'",
|
||||||
|
"output_type": "error",
|
||||||
"traceback": [
|
"traceback": [
|
||||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||||
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
|
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
|
||||||
"\u001b[0;32m<ipython-input-6-80ee186598d3>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mparser\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mParser\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mparser\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_get\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0mparser\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__parse\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
|
"\u001b[0;32m<ipython-input-6-80ee186598d3>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mparser\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mParser\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mparser\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_get\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0mparser\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__parse\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
|
||||||
"\u001b[0;31mAttributeError\u001b[0m: 'Parser' object has no attribute '__parse'"
|
"\u001b[0;31mAttributeError\u001b[0m: 'Parser' object has no attribute '__parse'"
|
||||||
],
|
]
|
||||||
"output_type": "error"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
@ -465,13 +465,13 @@
|
|||||||
{
|
{
|
||||||
"ename": "FileNotFoundError",
|
"ename": "FileNotFoundError",
|
||||||
"evalue": "[Errno 2] No such file or directory: 'nieistniejący_plik.txt'",
|
"evalue": "[Errno 2] No such file or directory: 'nieistniejący_plik.txt'",
|
||||||
|
"output_type": "error",
|
||||||
"traceback": [
|
"traceback": [
|
||||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||||
"\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
|
"\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
|
||||||
"\u001b[0;32m<ipython-input-20-41928d542bef>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mwith\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"nieistniejący_plik.txt\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mplik\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mplik\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
"\u001b[0;32m<ipython-input-20-41928d542bef>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mwith\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"nieistniejący_plik.txt\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mplik\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mplik\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||||
"\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'nieistniejący_plik.txt'"
|
"\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'nieistniejący_plik.txt'"
|
||||||
],
|
]
|
||||||
"output_type": "error"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
@ -614,13 +614,13 @@
|
|||||||
{
|
{
|
||||||
"ename": "MyError",
|
"ename": "MyError",
|
||||||
"evalue": "Coś poszło nie tak!",
|
"evalue": "Coś poszło nie tak!",
|
||||||
|
"output_type": "error",
|
||||||
"traceback": [
|
"traceback": [
|
||||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||||
"\u001b[0;31mMyError\u001b[0m Traceback (most recent call last)",
|
"\u001b[0;31mMyError\u001b[0m Traceback (most recent call last)",
|
||||||
"\u001b[0;32m<ipython-input-36-4fb306b42ebc>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mMyError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Coś poszło nie tak!\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
|
"\u001b[0;32m<ipython-input-36-4fb306b42ebc>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mMyError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Coś poszło nie tak!\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
|
||||||
"\u001b[0;31mMyError\u001b[0m: Coś poszło nie tak!"
|
"\u001b[0;31mMyError\u001b[0m: Coś poszło nie tak!"
|
||||||
],
|
]
|
||||||
"output_type": "error"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
|
@ -1,10 +1,3 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
def is_numeric(lista):
|
|
||||||
result=[]
|
|
||||||
for i in range(len(lista)):
|
|
||||||
result.append(isinstance(lista[i], (int,float)))
|
|
||||||
print (result)
|
|
||||||
|
|
||||||
is_numeric([1,'a',3.7])
|
|
@ -1,8 +1,3 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
class Employee:
|
|
||||||
def __init__(self, imie, nazwisko):
|
|
||||||
|
|
||||||
def get_id():
|
|
||||||
return(id)
|
|
@ -1,56 +1,3 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
#Zaimplementuj własny wyjątek ``DimensionError``, który zostaje wyrzucony, jeżeli dodawany punkt ma inny wymiar.
|
|
||||||
class DimensionError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
#Stwórz klasę ``Point``, która będzie reprezentować punkt w przestrzeni wielowymiarowej:
|
|
||||||
class Point:
|
|
||||||
# * Konstruktor ma przyjąc tylko 1 parametr: listę współrzednych.
|
|
||||||
def __init__(self, vertexes):
|
|
||||||
self.vertexes = vertexes
|
|
||||||
|
|
||||||
#sprawdź, czy lista zawiera wyłącznie liczby.
|
|
||||||
def is_numeric(vertexes):
|
|
||||||
if isinstance(vertexes,(float,int))==True:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
print("list does not contain only numbers")
|
|
||||||
|
|
||||||
#Napisz metodę add, która doda dwa punkty po współrzędnych i zwróci obiekt typu ``Punkt``. Zaimplementuj własny wyjątek ``DimensionError``, który zostaje wyrzucony, jeżeli dodawany punkt ma inny wymiar.
|
|
||||||
def add(self, newpoint):
|
|
||||||
sum=[]
|
|
||||||
if len(newpoint)!=len(self.vertexes):
|
|
||||||
raise DimensionError("Dimensions does not match")
|
|
||||||
else:
|
|
||||||
for i in range(len(newpoint)):
|
|
||||||
sum.append(self.vertexes[i] + newpoint[i])
|
|
||||||
return Point(sum)
|
|
||||||
|
|
||||||
|
|
||||||
#Napisz metodę ``to\_string``, która zwróci łancuch znakowy, który w czytelny sposób przedstawi punkt.
|
|
||||||
def to_string(self):
|
|
||||||
return str(self.vertexes)
|
|
||||||
def __to_string__(self):
|
|
||||||
return self.to_string()
|
|
||||||
#Napisz metodę __len__, która zwróci liczbę współrzędnych punktu.
|
|
||||||
def how_many(self):
|
|
||||||
return len(self.vertexes)
|
|
||||||
def __len__(self):
|
|
||||||
return self.how_many()
|
|
||||||
|
|
||||||
#Zobacz, czy możesz teraz wywołać funkcję len na obiekcie typu punkt.
|
|
||||||
figures = [2,1,3,4,2,7]
|
|
||||||
my_point = Point(figures)
|
|
||||||
no_of_coordinates=len(my_point)
|
|
||||||
print("Number of coordinates: ")
|
|
||||||
print(no_of_coordinates)
|
|
||||||
|
|
||||||
#Wyświetl obiekt typy Point korzystając z funkcji print.
|
|
||||||
print("Coordinates as a string: ")
|
|
||||||
print(my_point.to_string())
|
|
||||||
|
|
||||||
B=[2,1,2,3,1]
|
|
||||||
my_sum=Point(B)
|
|
||||||
my_point.add(B)
|
|
||||||
|
@ -1,36 +1,15 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import os;
|
|
||||||
os.chdir('J:\PycharmProjects\Python2017\labs06')
|
|
||||||
import pandas as pd
|
|
||||||
import numpy as np
|
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
import matplotlib
|
|
||||||
matplotlib.style.use('ggplot')
|
|
||||||
plt.rcParams['figure.figsize'] = (15, 5)
|
|
||||||
|
|
||||||
def wczytaj_dane():
|
def wczytaj_dane():
|
||||||
dane = pd.read_csv('mieszkania.csv', sep=',')
|
|
||||||
dane.rename(columns={'Unnamed: 11': 'Borough'}, inplace=True)
|
|
||||||
#type(dane)
|
|
||||||
#print(dane.head())
|
|
||||||
return(dane)
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def most_common_room_number(dane):
|
def most_common_room_number(dane):
|
||||||
m = dane.groupby(['Rooms']).count()
|
|
||||||
return(m['Id'].idxmax())
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def cheapest_flats(dane, n):
|
def cheapest_flats(dane, n):
|
||||||
dane2 = dane.sort_values(by=['Expected'])
|
|
||||||
return(dane2.head(n))
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def find_borough(desc):
|
def find_borough(desc):
|
||||||
dzielnice = ['Stare Miasto',
|
dzielnice = ['Stare Miasto',
|
||||||
'Wilda',
|
'Wilda',
|
||||||
@ -40,54 +19,24 @@ def find_borough(desc):
|
|||||||
'Winogrady',
|
'Winogrady',
|
||||||
'Miłostowo',
|
'Miłostowo',
|
||||||
'Dębiec']
|
'Dębiec']
|
||||||
tekst = desc.split(" ")
|
|
||||||
for i in range(len(tekst)):
|
|
||||||
for j in range(len(dzielnice)):
|
|
||||||
if tekst[i] == dzielnice[j]:
|
|
||||||
return(dzielnice[j])
|
|
||||||
else:
|
|
||||||
j = j + 1
|
|
||||||
i = i + 1
|
|
||||||
return('Inne')
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def add_borough(dane):
|
def add_borough(dane):
|
||||||
for i in range(5000):#len(dane.axes[0])):
|
|
||||||
dane['Borough'][i] = find_borough(dane['Location'][i])
|
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def write_plot(dane, filename):
|
def write_plot(dane, filename):
|
||||||
my_plot = dane['Borough'].hist()
|
|
||||||
fig = my_plot.get_figure()
|
|
||||||
|
|
||||||
dir_name = 'J:/PycharmProjects/Python2017/labs06/'
|
|
||||||
filename_suffix = 'pdf'
|
|
||||||
fig.savefig(os.path.join(dir_name, filename + "." + filename_suffix))
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def mean_price(dane, room_number):
|
def mean_price(dane, room_number):
|
||||||
m = dane.groupby(['Rooms']).mean()
|
|
||||||
return(m['Expected'][room_number])
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def find_13(dane):
|
def find_13(dane):
|
||||||
df_filtered = dane[dane['Floor'] == 13]
|
|
||||||
return(df_filtered['Borough'])
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def find_best_flats(dane):
|
def find_best_flats(dane):
|
||||||
df_filtered = dane[dane['Floor'] == 1]
|
|
||||||
df_filtered2=df_filtered[df_filtered['Borough']=='Winogrady']
|
|
||||||
df_filtered3 = df_filtered2[df_filtered2['Rooms'] == 3]
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
dane = wczytaj_dane()
|
dane = wczytaj_dane()
|
||||||
print(dane[:5])
|
print(dane[:5])
|
||||||
@ -96,7 +45,7 @@ def main():
|
|||||||
.format(most_common_room_number(dane)))
|
.format(most_common_room_number(dane)))
|
||||||
|
|
||||||
print("{} to najłądniejsza dzielnica w Poznaniu."
|
print("{} to najłądniejsza dzielnica w Poznaniu."
|
||||||
.format(find_borough("Grunwald i Jeżyce")))
|
.format(find_borough("Grunwald i Jeżyce"))))
|
||||||
|
|
||||||
print("Średnia cena mieszkania 3-pokojowego, to: {}"
|
print("Średnia cena mieszkania 3-pokojowego, to: {}"
|
||||||
.format(mean_price(dane, 3)))
|
.format(mean_price(dane, 3)))
|
||||||
|
Loading…
Reference in New Issue
Block a user