Compare commits
28 Commits
Author | SHA1 | Date | |
---|---|---|---|
e0d6872eda | |||
14ba0bb0ea | |||
6bce9cdb6a | |||
6f36635a56 | |||
f499b8eccd | |||
cbb941187a | |||
5a79c51337 | |||
984bf73c46 | |||
b986a45879 | |||
c8afe1950d | |||
31b4bae680 | |||
a7441350a1 | |||
ac794e117c | |||
090a391b68 | |||
e1ae7f9cae | |||
66007e3252 | |||
70554cf013 | |||
b52078b610 | |||
c941f0f6ac | |||
7cc01637fb | |||
c6901ebfc2 | |||
a946cb82da | |||
e1c9346baa | |||
36e78f1dfa | |||
77ffeebaea | |||
384abbe074 | |||
fd2448691d | |||
e604060124 |
@ -7,7 +7,7 @@ która zawiera tylko elementy z list o parzystych indeksach.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def even_elements(lista):
|
def even_elements(lista):
|
||||||
pass
|
return(lista[::2])
|
||||||
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
|
@ -5,8 +5,11 @@
|
|||||||
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(days):
|
def days_in_year(years):
|
||||||
pass
|
if (years % 4 == 0 and years % 100 != 0) or years % 400 == 0:
|
||||||
|
return 366
|
||||||
|
else:
|
||||||
|
return 365
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [[2015], [2012], [1900], [2400], [1977]]
|
inputs = [[2015], [2012], [1900], [2400], [1977]]
|
||||||
|
@ -13,7 +13,12 @@ jak 'set', która przechowuje elementy bez powtórzeń.)
|
|||||||
|
|
||||||
|
|
||||||
def oov(text, vocab):
|
def oov(text, vocab):
|
||||||
pass
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,8 +7,14 @@ 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):
|
||||||
pass
|
suma = 0
|
||||||
|
|
||||||
|
for i in range(n+1):
|
||||||
|
suma = suma + i
|
||||||
|
if n < 1:
|
||||||
|
return 0
|
||||||
|
else:
|
||||||
|
return suma
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [[999], [-100]]
|
inputs = [[999], [-100]]
|
||||||
|
@ -8,9 +8,10 @@ dwoma punktami przestrzeni trójwymiarowej. Punkty są dane jako
|
|||||||
trzyelementowe listy liczb zmiennoprzecinkowych.
|
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.
|
||||||
"""
|
"""
|
||||||
|
from math import sqrt
|
||||||
def euclidean_distance(x, y):
|
def euclidean_distance(x, y):
|
||||||
pass
|
|
||||||
|
return sqrt(sum((x - y) ** 2 for x, y in zip(x, y)))
|
||||||
|
|
||||||
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,7 +10,11 @@ ma być zwracany napis "It's not a Big 'No!'".
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def big_no(n):
|
def big_no(n):
|
||||||
pass
|
napis = 'N'
|
||||||
|
if n < 5:
|
||||||
|
return "It's not a Big 'No!'"
|
||||||
|
else:
|
||||||
|
return napis + n * 'O' + '!'
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [[5], [6], [2]]
|
inputs = [[5], [6], [2]]
|
||||||
|
@ -6,7 +6,10 @@ 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):
|
||||||
pass
|
suma = 0
|
||||||
|
for c in text:
|
||||||
|
suma += ord(c)
|
||||||
|
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,7 +7,12 @@ przez 3 lub 5 mniejszych niż n.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def sum_div35(n):
|
def sum_div35(n):
|
||||||
pass
|
suma = 0
|
||||||
|
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,8 +9,16 @@ Np. leet('leet') powinno zwrócić '1337'.
|
|||||||
|
|
||||||
|
|
||||||
def leet_speak(text):
|
def leet_speak(text):
|
||||||
pass
|
slownik = {'e':3, 'l':1, 'o':0, 't':7}
|
||||||
|
dekod = ''
|
||||||
|
|
||||||
|
for znak in text:
|
||||||
|
if znak in slownik:
|
||||||
|
dekod += str(slownik[znak])
|
||||||
|
else:
|
||||||
|
dekod += znak
|
||||||
|
|
||||||
|
return dekod
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [['leet'], ['do not want']]
|
inputs = [['leet'], ['do not want']]
|
||||||
|
@ -9,8 +9,16 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
|
|||||||
|
|
||||||
|
|
||||||
def pokemon_speak(text):
|
def pokemon_speak(text):
|
||||||
pass
|
wynik = ''
|
||||||
|
switch = 1
|
||||||
|
for znak in text:
|
||||||
|
if switch == 1:
|
||||||
|
wynik += znak.upper()
|
||||||
|
switch *= -1
|
||||||
|
else:
|
||||||
|
wynik += znak
|
||||||
|
switch *= -1
|
||||||
|
return wynik
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [['pokemon'], ['do not want'], ['POKEMON']]
|
inputs = [['pokemon'], ['do not want'], ['POKEMON']]
|
||||||
|
@ -9,8 +9,12 @@ Oba napisy będą składać się wyłacznie z małych liter.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def common_chars(string1, string2):
|
def common_chars(string1, string2):
|
||||||
pass
|
wspolne = []
|
||||||
|
|
||||||
|
for z in string1.replace(" ", ""):
|
||||||
|
if z in string2.replace(" ", "") and z not in wspolne:
|
||||||
|
wspolne.append(z)
|
||||||
|
return sorted(wspolne)
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [["this is a string", "ala ma kota"]]
|
inputs = [["this is a string", "ala ma kota"]]
|
||||||
|
31
labs03/task01.py
Normal file
31
labs03/task01.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
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')
|
14
labs03/task02.py
Normal file
14
labs03/task02.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#!/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)
|
26
labs03/task05.py
Normal file
26
labs03/task05.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#!/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,3 +1,74 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
# -*- coding: utf-8 -*-
|
# -*- 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 sys
|
||||||
|
import argparse
|
||||||
|
|
||||||
def count_lines(text):
|
def count_lines(text):
|
||||||
""" return number of lines. """
|
""" return number of lines. """
|
||||||
@ -32,8 +32,31 @@ def wc(text):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
""" 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__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
@ -1,14 +1,24 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import pandas as pd
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
|
||||||
def wczytaj_dane():
|
def wczytaj_dane():
|
||||||
pass
|
csv_data = pd.read_csv('mieszkania.csv', index_col='Id')
|
||||||
|
return pd.DataFrame(csv_data)
|
||||||
|
|
||||||
|
|
||||||
def most_common_room_number(dane):
|
def most_common_room_number(dane):
|
||||||
pass
|
|
||||||
|
dane_agg = dane["Rooms"].value_counts()
|
||||||
|
return dane_agg.index.tolist()[0]
|
||||||
|
|
||||||
|
|
||||||
def cheapest_flats(dane, n):
|
def cheapest_flats(dane, n):
|
||||||
pass
|
dane_cheapest = dane.sort_values(by=["Expected"])[:n]
|
||||||
|
return dane_cheapest
|
||||||
|
|
||||||
|
|
||||||
def find_borough(desc):
|
def find_borough(desc):
|
||||||
dzielnice = ['Stare Miasto',
|
dzielnice = ['Stare Miasto',
|
||||||
@ -19,36 +29,72 @@ def find_borough(desc):
|
|||||||
'Winogrady',
|
'Winogrady',
|
||||||
'Miłostowo',
|
'Miłostowo',
|
||||||
'Dębiec']
|
'Dębiec']
|
||||||
pass
|
first = ""
|
||||||
|
found = False
|
||||||
|
for dz in dzielnice:
|
||||||
|
if dz in desc:
|
||||||
|
first = dz
|
||||||
|
found = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if not found:
|
||||||
|
return 'Inne'
|
||||||
|
else:
|
||||||
|
return first
|
||||||
|
|
||||||
|
|
||||||
def add_borough(dane):
|
def add_borough(dane):
|
||||||
pass
|
dane['Borough'] = dane['Location'].map(lambda loc: find_borough(loc))
|
||||||
|
|
||||||
|
|
||||||
def write_plot(dane, filename):
|
def write_plot(dane, filename):
|
||||||
pass
|
|
||||||
|
dane['Borough'].value_counts().plot(kind='bar', figsize = (10, 10))
|
||||||
|
plt.savefig(filename)
|
||||||
|
|
||||||
|
|
||||||
def mean_price(dane, room_number):
|
def mean_price(dane, room_number):
|
||||||
pass
|
ff = dane[dane['Rooms'] == room_number]
|
||||||
|
return ff['Expected'].mean()
|
||||||
|
|
||||||
|
|
||||||
def find_13(dane):
|
def find_13(dane):
|
||||||
pass
|
|
||||||
|
ff = dane[dane['Floor'] == 13]
|
||||||
|
return ff['Borough'].unique()
|
||||||
|
|
||||||
|
|
||||||
def find_best_flats(dane):
|
def find_best_flats(dane):
|
||||||
pass
|
|
||||||
|
bf = dane[(dane['Rooms'] == 3) & (dane['Floor'] == 1) & (dane['Borough'] == 'Winogrady')]
|
||||||
|
return bf
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
dane = wczytaj_dane()
|
dane = wczytaj_dane()
|
||||||
|
add_borough(dane)
|
||||||
print(dane[:5])
|
print(dane[:5])
|
||||||
|
|
||||||
|
|
||||||
print("Najpopularniejsza liczba pokoi w mieszkaniu to: {}"
|
print("Najpopularniejsza liczba pokoi w mieszkaniu to: {}"
|
||||||
.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)))
|
||||||
|
|
||||||
|
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__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
Loading…
Reference in New Issue
Block a user