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
|
||||
---------|-----------------|-----------------|-----------------|-----------------|---------------
|
||||
s45168 | 0 | 0 | 0 | 0 | 0
|
||||
s45162 | 1 | 1 | 1 | 1 | 1
|
||||
s45158 | 1 | 1 | 0 | 0 | 1
|
||||
szwedek | 1 | 1 | 1 | 1 | 1
|
||||
s45155 | 1 | 1 | 1 | 1 | 1
|
||||
s45152 | 1 | 1 | 1 | 0 | 1
|
||||
s45148 | 1 | 1 | 1 | 1 | 1
|
||||
s45166 | 1 | 1 | 1 | 1 | 1
|
||||
s45151 | 1 | 1 | 1 | 1 | 1
|
||||
s45146 | 1 | 1 | 1 | 1 | 1
|
||||
s45150 | 1 | 1 | 1 | 1 | 1
|
||||
s45452 | 1 | 1 | 1 | 1 | 1
|
||||
s45165 | 1 | 1 | 1 | 1 | 1
|
||||
s45160 | 1 | 1 | 1 | 1 | 1
|
||||
s45153 | 0 | 0 | 0 | 0 | 0
|
||||
s45156 | 1 | 1 | 1 | 1 | 1
|
||||
s45157 | 0 | 0 | 1 | 1 | 1
|
||||
s45167 | 1 | 1 | 1 | 1 | 1
|
||||
s45147 | 1 | 0 | 0 | 1 | 0
|
||||
s45159 | 0 | 0 | 0 | 0 | 0
|
||||
s45161 | 1 | 1 | 1 | 1 | 1
|
||||
s45164 | 1 | 1 | 0 | 1 | 0
|
||||
ID | labs02:task07 | labs02:task08 | labs02:task09 | labs02:task10 | labs02:task11 | labs03 | labs04 | labs06 | Punkty | Ocena |
|
||||
---------|-----------------|-----------------|-----------------|-----------------|-----------------|----------|----------|----------|--------|-------|
|
||||
s45146 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||
s45147 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||
s45148 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||
s45150 | 1 | 1 | 1 | 1 | 1 | 2 | 1 | 8 | 16 | 4 |
|
||||
s45151 | 1 | 1 | 1 | 1 | 1 | 0 | 5 | 8 | 18 | 4.5 |
|
||||
s45152 | 1 | 1 | 1 | 0 | 1 | 0 | 5 | 8 | 17 | 4 |
|
||||
s45153 | 0 | 1 | 1 | 1 | 1 | 4 | 0 | 8 | 16 | 4 |
|
||||
s45155 | 1 | 1 | 1 | 1 | 1 | 1 | 5 | 8 | 19 | 4.5 |
|
||||
s45156 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||
s45157 | 1 | 1 | 1 | 1 | 1 | 4 | 4 | 8 | 21 | 5 |
|
||||
s45158 | 1 | 1 | 0 | 0 | 1 | 4 | 5 | 8 | 19 | 4.5 |
|
||||
s45159 | 1 | 1 | 1 | 1 | 1 | 2 | 3 | 8 | 18 | 4.5 |
|
||||
s45160 | 1 | 1 | 1 | 1 | 1 | 4 | 4 | 8 | 21 | 5 |
|
||||
s45161 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||
s45162 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||
s45163 | 1 | 1 | 1 | 1 | 1 | 4 | 4 | 8 | 21 | 5 |
|
||||
s45164 | 1 | 1 | 0 | 1 | 0 | 0 | 5 | 8 | 16 | 4 |
|
||||
s45165 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||
s45166 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||
s45167 | 1 | 1 | 1 | 1 | 1 | 0 | 5 | 8 | 17 | 4 |
|
||||
s45168 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 |
|
||||
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):
|
||||
return(lista[::2])
|
||||
pass
|
||||
|
||||
|
||||
def tests(f):
|
||||
|
@ -5,11 +5,8 @@
|
||||
Napisz funkcję days_in_year zwracającą liczbę dni w roku (365 albo 366).
|
||||
"""
|
||||
|
||||
def days_in_year(years):
|
||||
if (years % 4 == 0 and years % 100 != 0) or years % 400 == 0:
|
||||
return 366
|
||||
else:
|
||||
return 365
|
||||
def days_in_year(days):
|
||||
pass
|
||||
|
||||
def tests(f):
|
||||
inputs = [[2015], [2012], [1900], [2400], [1977]]
|
||||
|
@ -13,12 +13,7 @@ jak 'set', która przechowuje elementy bez powtórzeń.)
|
||||
|
||||
|
||||
def oov(text, vocab):
|
||||
list_of_words = []
|
||||
text_splitted = text.split(' ')
|
||||
for word in text_splitted:
|
||||
if word.lower() not in vocab:
|
||||
list_of_words.append(word.lower())
|
||||
return set(list_of_words)
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
@ -7,14 +7,8 @@ Jeśli podany argument jest mniejszy od 1 powinna być zwracana wartość 0.
|
||||
"""
|
||||
|
||||
def sum_from_one_to_n(n):
|
||||
suma = 0
|
||||
pass
|
||||
|
||||
for i in range(n+1):
|
||||
suma = suma + i
|
||||
if n < 1:
|
||||
return 0
|
||||
else:
|
||||
return suma
|
||||
|
||||
def tests(f):
|
||||
inputs = [[999], [-100]]
|
||||
|
@ -8,10 +8,9 @@ dwoma punktami przestrzeni trójwymiarowej. Punkty są dane jako
|
||||
trzyelementowe listy liczb zmiennoprzecinkowych.
|
||||
np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5.
|
||||
"""
|
||||
from math import sqrt
|
||||
def euclidean_distance(x, y):
|
||||
|
||||
return sqrt(sum((x - y) ** 2 for x, y in zip(x, y)))
|
||||
def euclidean_distance(x, y):
|
||||
pass
|
||||
|
||||
def tests(f):
|
||||
inputs = [[(2.3, 4.3, -7.5), (2.3, 8.5, -7.5)]]
|
||||
|
@ -10,11 +10,7 @@ ma być zwracany napis "It's not a Big 'No!'".
|
||||
"""
|
||||
|
||||
def big_no(n):
|
||||
napis = 'N'
|
||||
if n < 5:
|
||||
return "It's not a Big 'No!'"
|
||||
else:
|
||||
return napis + n * 'O' + '!'
|
||||
pass
|
||||
|
||||
def tests(f):
|
||||
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.
|
||||
"""
|
||||
def char_sum(text):
|
||||
suma = 0
|
||||
for c in text:
|
||||
suma += ord(c)
|
||||
return suma
|
||||
pass
|
||||
|
||||
def tests(f):
|
||||
inputs = [["this is a string"], ["this is another string"]]
|
||||
|
@ -7,12 +7,7 @@ przez 3 lub 5 mniejszych niż n.
|
||||
"""
|
||||
|
||||
def sum_div35(n):
|
||||
suma = 0
|
||||
for i in range(n):
|
||||
if i%3 == 0 or i%5 == 0:
|
||||
suma += i
|
||||
|
||||
return suma
|
||||
pass
|
||||
|
||||
def tests(f):
|
||||
inputs = [[10], [100], [3845]]
|
||||
|
@ -9,16 +9,8 @@ Np. leet('leet') powinno zwrócić '1337'.
|
||||
|
||||
|
||||
def leet_speak(text):
|
||||
slownik = {'e':3, 'l':1, 'o':0, 't':7}
|
||||
dekod = ''
|
||||
pass
|
||||
|
||||
for znak in text:
|
||||
if znak in slownik:
|
||||
dekod += str(slownik[znak])
|
||||
else:
|
||||
dekod += znak
|
||||
|
||||
return dekod
|
||||
|
||||
def tests(f):
|
||||
inputs = [['leet'], ['do not want']]
|
||||
|
@ -9,16 +9,8 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
|
||||
|
||||
|
||||
def pokemon_speak(text):
|
||||
wynik = ''
|
||||
switch = 1
|
||||
for znak in text:
|
||||
if switch == 1:
|
||||
wynik += znak.upper()
|
||||
switch *= -1
|
||||
else:
|
||||
wynik += znak
|
||||
switch *= -1
|
||||
return wynik
|
||||
pass
|
||||
|
||||
|
||||
def tests(f):
|
||||
inputs = [['pokemon'], ['do not want'], ['POKEMON']]
|
||||
|
@ -9,12 +9,8 @@ Oba napisy będą składać się wyłacznie z małych liter.
|
||||
"""
|
||||
|
||||
def common_chars(string1, string2):
|
||||
wspolne = []
|
||||
pass
|
||||
|
||||
for z in string1.replace(" ", ""):
|
||||
if z in string2.replace(" ", "") and z not in wspolne:
|
||||
wspolne.append(z)
|
||||
return sorted(wspolne)
|
||||
|
||||
def tests(f):
|
||||
inputs = [["this is a string", "ala ma kota"]]
|
||||
|
@ -1,31 +0,0 @@
|
||||
lista = [1, 2, 3]
|
||||
|
||||
a=id(lista)
|
||||
b=id(lista)
|
||||
|
||||
if a == b:
|
||||
print('Lista Immutable')
|
||||
else:
|
||||
print('Lista Mutable')
|
||||
|
||||
napis = 'Napis'
|
||||
|
||||
c=id(napis)
|
||||
d=id(napis)
|
||||
|
||||
if c == d:
|
||||
print('Napis Immutable')
|
||||
else:
|
||||
print('Napis Mutable')
|
||||
|
||||
liczba=23.34
|
||||
|
||||
e=id(liczba)
|
||||
f=id(liczba)
|
||||
|
||||
if e == f:
|
||||
print('Liczba Immutable')
|
||||
else:
|
||||
print('Liczba Mutable')
|
||||
|
||||
print('Koniec')
|
@ -1,14 +0,0 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
def fibonacci(n):
|
||||
fn = [0, 1,]
|
||||
for i in range(2, n):
|
||||
fn.append(fn[i-1] + fn[i-2])
|
||||
yield fn
|
||||
|
||||
|
||||
a = fibonacci(10)
|
||||
for i in a:
|
||||
print(i)
|
@ -1,26 +0,0 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import glob
|
||||
|
||||
path = 'scores'
|
||||
os.chdir(path)
|
||||
|
||||
max_file_name = ''
|
||||
max_bleu = 0
|
||||
|
||||
file_list = glob.glob('model.iter[0-9][0-9][0-9][0-9][0-9].npz.bleu') + glob.glob('model.iter[0-9][0-9][0-9][0-9][0-9][0-9].npz.bleu')
|
||||
|
||||
for file in file_list:
|
||||
with open(file, 'r') as f:
|
||||
for line in f.readlines():
|
||||
fc = line.find(',')
|
||||
feq = line.find('=') + 1
|
||||
|
||||
bleu = float(line[feq:fc])
|
||||
|
||||
if bleu > max_bleu:
|
||||
max_bleu = bleu
|
||||
max_file_name = file
|
||||
|
||||
print(os.getcwd() + '\\' + max_file_name)
|
@ -1,74 +1,3 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
def is_numeric(x):
|
||||
|
||||
ile = len(x)
|
||||
licznik = 0
|
||||
|
||||
for i in x:
|
||||
if isinstance(i, (int, float)):
|
||||
licznik += 1
|
||||
|
||||
if ile == licznik:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def add_coordinates(c1, c2):
|
||||
new = []
|
||||
if len(c1) == len(c2):
|
||||
for i in range(0, len(c1)):
|
||||
new.append(c1[i]+c2[i])
|
||||
return new
|
||||
|
||||
|
||||
class DimensionError(Exception):
|
||||
def __init__(self, text):
|
||||
self.text = text
|
||||
|
||||
def __str__(self):
|
||||
return self.text
|
||||
|
||||
|
||||
class Point:
|
||||
def __init__(self, coordinates):
|
||||
|
||||
if not is_numeric(coordinates):
|
||||
raise Exception('Lista zawiera wartosci nieliczbowe')
|
||||
self.coordinates = coordinates
|
||||
|
||||
self.coordinates_to_string = 'Koordynaty punktu: ['
|
||||
for c in coordinates:
|
||||
self.coordinates_to_string += str(c) + ', '
|
||||
self.coordinates_to_string = self.coordinates_to_string[:-2]
|
||||
self.coordinates_to_string += ']'
|
||||
|
||||
def to_string(self):
|
||||
print(self.coordinates_to_string)
|
||||
|
||||
def __str__(self):
|
||||
return self.coordinates_to_string
|
||||
|
||||
def __add__(self, other):
|
||||
if len(self.coordinates) != len(other.coordinates):
|
||||
raise DimensionError('Punkty maja rozne wymiary')
|
||||
|
||||
return Point(add_coordinates(self.coordinates, other.coordinates))
|
||||
|
||||
def __len__(self):
|
||||
return len(self.coordinates)
|
||||
|
||||
|
||||
a = Point([1, 1, 5])
|
||||
b = Point([2, 4, 4])
|
||||
|
||||
print(a)
|
||||
b.to_string()
|
||||
print(len(b))
|
||||
|
||||
c = a + b
|
||||
print(c)
|
||||
|
||||
|
@ -7,7 +7,7 @@ Zwraca liczbę słów, znaków i linii.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
|
||||
def count_lines(text):
|
||||
""" return number of lines. """
|
||||
@ -32,31 +32,8 @@ def wc(text):
|
||||
|
||||
def main():
|
||||
""" main """
|
||||
print(wc(sys.stdin.read()))
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-l", help="-l switch returns number of lines", action='store_true')
|
||||
parser.add_argument("-w", help="-w switch returns number of words", action='store_true')
|
||||
parser.add_argument("-c", help="-c switch returns number of characters", action='store_true')
|
||||
parser.add_argument("filename", help="path to a file to read from", type=argparse.FileType('rt'), nargs='?')
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.filename is None:
|
||||
readinput = sys.stdin.read()
|
||||
else:
|
||||
readinput = args.filename.read()
|
||||
|
||||
outputmsg = ""
|
||||
|
||||
if args.l:
|
||||
outputmsg = "Number of typed lines: {}".format(count_lines(readinput))
|
||||
elif args.w:
|
||||
outputmsg = "Number of typed words: {}".format(count_words(readinput))
|
||||
elif args.c:
|
||||
outputmsg = "Number of typed characters: {}".format(count_chars(readinput))
|
||||
else:
|
||||
outputmsg = "Number of typed (lines, words, characters): {}".format(wc(readinput))
|
||||
|
||||
print(outputmsg)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
@ -1,24 +1,14 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
def wczytaj_dane():
|
||||
csv_data = pd.read_csv('mieszkania.csv', index_col='Id')
|
||||
return pd.DataFrame(csv_data)
|
||||
|
||||
pass
|
||||
|
||||
def most_common_room_number(dane):
|
||||
|
||||
dane_agg = dane["Rooms"].value_counts()
|
||||
return dane_agg.index.tolist()[0]
|
||||
|
||||
pass
|
||||
|
||||
def cheapest_flats(dane, n):
|
||||
dane_cheapest = dane.sort_values(by=["Expected"])[:n]
|
||||
return dane_cheapest
|
||||
|
||||
pass
|
||||
|
||||
def find_borough(desc):
|
||||
dzielnice = ['Stare Miasto',
|
||||
@ -29,72 +19,36 @@ def find_borough(desc):
|
||||
'Winogrady',
|
||||
'Miłostowo',
|
||||
'Dębiec']
|
||||
first = ""
|
||||
found = False
|
||||
for dz in dzielnice:
|
||||
if dz in desc:
|
||||
first = dz
|
||||
found = True
|
||||
break
|
||||
|
||||
if not found:
|
||||
return 'Inne'
|
||||
else:
|
||||
return first
|
||||
pass
|
||||
|
||||
|
||||
def add_borough(dane):
|
||||
dane['Borough'] = dane['Location'].map(lambda loc: find_borough(loc))
|
||||
|
||||
pass
|
||||
|
||||
def write_plot(dane, filename):
|
||||
|
||||
dane['Borough'].value_counts().plot(kind='bar', figsize = (10, 10))
|
||||
plt.savefig(filename)
|
||||
|
||||
pass
|
||||
|
||||
def mean_price(dane, room_number):
|
||||
ff = dane[dane['Rooms'] == room_number]
|
||||
return ff['Expected'].mean()
|
||||
|
||||
pass
|
||||
|
||||
def find_13(dane):
|
||||
|
||||
ff = dane[dane['Floor'] == 13]
|
||||
return ff['Borough'].unique()
|
||||
|
||||
pass
|
||||
|
||||
def find_best_flats(dane):
|
||||
|
||||
bf = dane[(dane['Rooms'] == 3) & (dane['Floor'] == 1) & (dane['Borough'] == 'Winogrady')]
|
||||
return bf
|
||||
|
||||
pass
|
||||
|
||||
def main():
|
||||
|
||||
dane = wczytaj_dane()
|
||||
add_borough(dane)
|
||||
print(dane[:5])
|
||||
|
||||
|
||||
print("Najpopularniejsza liczba pokoi w mieszkaniu to: {}"
|
||||
.format(most_common_room_number(dane)))
|
||||
|
||||
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: {}"
|
||||
.format(mean_price(dane, 3)))
|
||||
|
||||
print("Dzielnice z mieszkaniami na 13 piętrze, to: {}"
|
||||
.format(find_13(dane)))
|
||||
|
||||
ile = 10
|
||||
print("Najtańsze oferty mieszkań, to: {}"
|
||||
.format(cheapest_flats(dane, ile)))
|
||||
|
||||
write_plot(dane, 'mieszkania_plot.png')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue
Block a user