Compare commits

...

28 Commits

Author SHA1 Message Date
e0d6872eda task04 ok 2017-12-31 13:37:11 +01:00
14ba0bb0ea task02 ok 2017-12-23 19:18:52 +01:00
6bce9cdb6a task11 fixed 2017-12-16 20:27:32 +01:00
6f36635a56 task09 fixed 2017-12-16 20:06:49 +01:00
f499b8eccd task08 fixed 2017-12-16 20:02:01 +01:00
cbb941187a Merge branch 'master' of https://git.wmi.amu.edu.pl/tdwojak/Python2017 2017-12-16 09:03:05 +01:00
5a79c51337 task05 done 2017-12-09 23:17:38 +01:00
984bf73c46 task02 done 2017-12-09 23:16:43 +01:00
b986a45879 task03 done 2017-12-09 23:14:23 +01:00
c8afe1950d Merge branch 'master' of https://git.wmi.amu.edu.pl/tdwojak/Python2017 2017-12-03 13:36:19 +01:00
31b4bae680 Task01 2017-12-02 15:43:44 +01:00
a7441350a1 Task01 2017-12-02 15:40:31 +01:00
ac794e117c Merge branch 'master' of https://git.wmi.amu.edu.pl/s45147/Python2017 2017-12-02 15:05:56 +01:00
090a391b68 done 2017-11-20 10:21:13 +01:00
e1ae7f9cae done 2017-11-20 10:19:15 +01:00
66007e3252 done 2017-11-20 10:17:48 +01:00
70554cf013 done 2017-11-20 10:11:11 +01:00
b52078b610 done 2017-11-20 09:56:26 +01:00
c941f0f6ac done 2017-11-20 09:43:00 +01:00
7cc01637fb done 2017-11-20 09:36:10 +01:00
c6901ebfc2 done 2017-11-20 09:32:51 +01:00
a946cb82da done 2017-11-19 15:40:09 +01:00
e1c9346baa done 2017-11-19 15:35:13 +01:00
36e78f1dfa done 2017-11-19 15:34:42 +01:00
77ffeebaea done 2017-11-19 15:29:24 +01:00
384abbe074 done 2017-11-19 15:11:38 +01:00
fd2448691d done 2017-11-19 14:57:58 +01:00
e604060124 done 2017-11-19 14:53:05 +01:00
17 changed files with 286 additions and 28 deletions

View File

@ -7,7 +7,7 @@ która zawiera tylko elementy z list o parzystych indeksach.
"""
def even_elements(lista):
pass
return(lista[::2])
def tests(f):

View File

@ -5,8 +5,11 @@
Napisz funkcję days_in_year zwracającą liczbę dni w roku (365 albo 366).
"""
def days_in_year(days):
pass
def days_in_year(years):
if (years % 4 == 0 and years % 100 != 0) or years % 400 == 0:
return 366
else:
return 365
def tests(f):
inputs = [[2015], [2012], [1900], [2400], [1977]]

View File

@ -13,7 +13,12 @@ jak 'set', która przechowuje elementy bez powtórzeń.)
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)

View File

@ -7,8 +7,14 @@ Jeśli podany argument jest mniejszy od 1 powinna być zwracana wartość 0.
"""
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):
inputs = [[999], [-100]]

View File

@ -8,9 +8,10 @@ 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):
pass
return sqrt(sum((x - y) ** 2 for x, y in zip(x, y)))
def tests(f):
inputs = [[(2.3, 4.3, -7.5), (2.3, 8.5, -7.5)]]

View File

@ -10,7 +10,11 @@ ma być zwracany napis "It's not a Big 'No!'".
"""
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):
inputs = [[5], [6], [2]]

View File

@ -6,7 +6,10 @@ Napisz funkcję char_sum, która dla zadanego łańcucha zwraca
sumę kodów ASCII znaków.
"""
def char_sum(text):
pass
suma = 0
for c in text:
suma += ord(c)
return suma
def tests(f):
inputs = [["this is a string"], ["this is another string"]]

View File

@ -7,7 +7,12 @@ przez 3 lub 5 mniejszych niż 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):
inputs = [[10], [100], [3845]]

View File

@ -9,8 +9,16 @@ Np. leet('leet') powinno zwrócić '1337'.
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):
inputs = [['leet'], ['do not want']]

View File

@ -9,8 +9,16 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
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):
inputs = [['pokemon'], ['do not want'], ['POKEMON']]

View File

@ -9,8 +9,12 @@ Oba napisy będą składać się wyłacznie z małych liter.
"""
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):
inputs = [["this is a string", "ala ma kota"]]

31
labs03/task01.py Normal file
View 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
View 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
View 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)

View File

@ -1,3 +1,74 @@
#!/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)

View File

@ -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,8 +32,31 @@ 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()

View File

@ -1,14 +1,24 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pandas as pd
import matplotlib.pyplot as plt
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):
pass
dane_agg = dane["Rooms"].value_counts()
return dane_agg.index.tolist()[0]
def cheapest_flats(dane, n):
pass
dane_cheapest = dane.sort_values(by=["Expected"])[:n]
return dane_cheapest
def find_borough(desc):
dzielnice = ['Stare Miasto',
@ -19,36 +29,72 @@ def find_borough(desc):
'Winogrady',
'Miłostowo',
'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):
pass
dane['Borough'] = dane['Location'].map(lambda loc: find_borough(loc))
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):
pass
ff = dane[dane['Rooms'] == room_number]
return ff['Expected'].mean()
def find_13(dane):
pass
ff = dane[dane['Floor'] == 13]
return ff['Borough'].unique()
def find_best_flats(dane):
pass
bf = dane[(dane['Rooms'] == 3) & (dane['Floor'] == 1) & (dane['Borough'] == 'Winogrady')]
return bf
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)))
.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()
main()