Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
a9c3dfe5bd | ||
|
dc99f2323d | ||
|
57a0325708 | ||
|
6cf371942e | ||
|
457d5f2146 | ||
|
8ee919ddd0 | ||
|
b4ddfb1971 | ||
|
a07b7a1613 |
@ -7,7 +7,8 @@ która zawiera tylko elementy z list o parzystych indeksach.
|
||||
"""
|
||||
|
||||
def even_elements(lista):
|
||||
pass
|
||||
x = lista[::2]
|
||||
return x
|
||||
|
||||
|
||||
def tests(f):
|
||||
|
@ -6,7 +6,13 @@
|
||||
"""
|
||||
|
||||
def days_in_year(days):
|
||||
pass
|
||||
if days % 4 == 0 and days % 100 != 0:
|
||||
return 366
|
||||
elif days % 400 == 0:
|
||||
return 366
|
||||
else:
|
||||
return 365
|
||||
|
||||
|
||||
def tests(f):
|
||||
inputs = [[2015], [2012], [1900], [2400], [1977]]
|
||||
|
@ -13,7 +13,12 @@ jak 'set', która przechowuje elementy bez powtórzeń.)
|
||||
|
||||
|
||||
def oov(text, vocab):
|
||||
pass
|
||||
finalList = []
|
||||
wordList = text.split(" ")
|
||||
for word in wordList:
|
||||
if word not in vocab:
|
||||
finalList.append(word)
|
||||
return finalList
|
||||
|
||||
|
||||
|
||||
|
@ -7,7 +7,10 @@ Jeśli podany argument jest mniejszy od 1 powinna być zwracana wartość 0.
|
||||
"""
|
||||
|
||||
def sum_from_one_to_n(n):
|
||||
pass
|
||||
if n < 1:
|
||||
return 0
|
||||
else:
|
||||
return sum(range(1,n+1))
|
||||
|
||||
|
||||
def tests(f):
|
||||
|
@ -9,8 +9,14 @@ trzyelementowe listy liczb zmiennoprzecinkowych.
|
||||
np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5.
|
||||
"""
|
||||
|
||||
import math
|
||||
def euclidean_distance(x, y):
|
||||
pass
|
||||
x1 = x[0]
|
||||
x2 = y[0]
|
||||
y1 = x[1]
|
||||
y2 = y[1]
|
||||
z = math.sqrt((x1-x2)**2+(y1-y2)**2)
|
||||
return z
|
||||
|
||||
def tests(f):
|
||||
inputs = [[(2.3, 4.3, -7.5), (2.3, 8.5, -7.5)]]
|
||||
|
@ -10,7 +10,12 @@ ma być zwracany napis "It's not a Big 'No!'".
|
||||
"""
|
||||
|
||||
def big_no(n):
|
||||
pass
|
||||
if n < 5:
|
||||
return "It's not a Big 'No!'"
|
||||
else:
|
||||
bigO = "O"*n
|
||||
return "N"+bigO+"!"
|
||||
|
||||
|
||||
def tests(f):
|
||||
inputs = [[5], [6], [2]]
|
||||
|
@ -6,7 +6,11 @@ Napisz funkcję char_sum, która dla zadanego łańcucha zwraca
|
||||
sumę kodów ASCII znaków.
|
||||
"""
|
||||
def char_sum(text):
|
||||
pass
|
||||
letterSum = 0
|
||||
for letter in text:
|
||||
letterSum += ord(letter)
|
||||
return letterSum
|
||||
|
||||
|
||||
def tests(f):
|
||||
inputs = [["this is a string"], ["this is another string"]]
|
||||
|
@ -7,7 +7,11 @@ przez 3 lub 5 mniejszych niż n.
|
||||
"""
|
||||
|
||||
def sum_div35(n):
|
||||
pass
|
||||
finalSum = 0
|
||||
for i in range(1,n):
|
||||
if i % 3 == 0 or i % 5 == 0:
|
||||
finalSum += i
|
||||
return finalSum
|
||||
|
||||
def tests(f):
|
||||
inputs = [[10], [100], [3845]]
|
||||
|
@ -9,7 +9,20 @@ Np. leet('leet') powinno zwrócić '1337'.
|
||||
|
||||
|
||||
def leet_speak(text):
|
||||
pass
|
||||
letterList = list(text)
|
||||
x = 0
|
||||
for i in letterList:
|
||||
if i == 'e':
|
||||
letterList[x] = '3'
|
||||
elif i == 'l':
|
||||
letterList[x] = '1'
|
||||
elif i == 'o':
|
||||
letterList[x] = '0'
|
||||
elif i == 't':
|
||||
letterList[x] = '7'
|
||||
x += 1
|
||||
finalOutput = ''.join(letterList)
|
||||
return finalOutput
|
||||
|
||||
|
||||
def tests(f):
|
||||
|
@ -9,7 +9,17 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
|
||||
|
||||
|
||||
def pokemon_speak(text):
|
||||
pass
|
||||
letterList = list(text)
|
||||
|
||||
x = 0
|
||||
for i in letterList:
|
||||
if i.isalpha() and (x == 0 or x % 2 == 0):
|
||||
letterList[x] = i.upper()
|
||||
x += 1
|
||||
finalOutput = ''.join(letterList)
|
||||
return finalOutput
|
||||
|
||||
|
||||
|
||||
|
||||
def tests(f):
|
||||
|
@ -9,7 +9,14 @@ Oba napisy będą składać się wyłacznie z małych liter.
|
||||
"""
|
||||
|
||||
def common_chars(string1, string2):
|
||||
pass
|
||||
finalList = []
|
||||
for i in string1:
|
||||
if i.isalpha() and i in string2 and i not in finalList:
|
||||
finalList.append(i)
|
||||
for j in string2:
|
||||
if j.isalpha() and j in string1 and j not in finalList:
|
||||
finalList.append(j)
|
||||
return sorted(finalList)
|
||||
|
||||
|
||||
def tests(f):
|
||||
|
47
labs03/task01.py
Normal file
47
labs03/task01.py
Normal file
@ -0,0 +1,47 @@
|
||||
# coding=utf-8
|
||||
'''
|
||||
**ćwiczenie 1**
|
||||
Każdy obiekt w Pythonie na wbudowaną funkcję ``id()``, która zwraca liczbę, która jest unikatowa i stała dla obiektu.
|
||||
Pozwala ona w prosty sposób sprawdzić, który obiekt jest *mutable*a, który *immutable*: jeżeli po wykonaniu operacji, zwracana liczba jest stała,
|
||||
to oznacza, że obiekt jest *mutable*. Sprawdź zachowanie funkcji na obiektach typy:
|
||||
* lista,
|
||||
* napis (string),
|
||||
* liczba zmiennoprzecinkowa.
|
||||
'''
|
||||
|
||||
def mutCheck(item):
|
||||
itemType = type(item)
|
||||
if itemType is list:
|
||||
id1 = id(item)
|
||||
item[0] = "X"
|
||||
id2 = id(item)
|
||||
if id1 == id2:
|
||||
return "List is mutable"
|
||||
else:
|
||||
return "List is inmutable"
|
||||
|
||||
elif itemType is str:
|
||||
id1 = id(item)
|
||||
item += "Pam"
|
||||
id2 = id(item)
|
||||
if id1 == id2:
|
||||
return "String is mutable"
|
||||
else:
|
||||
return "String is inmutable"
|
||||
|
||||
elif itemType is float:
|
||||
id1 = id(item)
|
||||
item += 1
|
||||
id2 = id(item)
|
||||
if id1 == id2:
|
||||
return "Float is mutable"
|
||||
else:
|
||||
return "Float is inmutable"
|
||||
|
||||
else:
|
||||
return "Given item is not a list, string or a float type"
|
||||
|
||||
toCheck = 2.1
|
||||
|
||||
x = mutCheck(toCheck)
|
||||
print x
|
18
labs03/task02.py
Normal file
18
labs03/task02.py
Normal file
@ -0,0 +1,18 @@
|
||||
# coding=utf-8
|
||||
'''
|
||||
**ćwiczenie 2**
|
||||
Napisz generator, który będzie zwracać ``n`` kolejnych liczb ciągu Fibonacciego (``F(0)=1, F(1)=1, FN=F(N-1) + F(N-2)``).
|
||||
'''
|
||||
|
||||
def fibbonacci():
|
||||
x = 0
|
||||
y = 1
|
||||
while True:
|
||||
yield x
|
||||
x, y = y, x+y
|
||||
|
||||
fibGen = fibbonacci()
|
||||
n = 5
|
||||
|
||||
for i in range(n):
|
||||
print fibGen.next()
|
17
labs03/task03.py
Normal file
17
labs03/task03.py
Normal file
@ -0,0 +1,17 @@
|
||||
# coding=utf-8
|
||||
"""
|
||||
**ćwiczenie 3**
|
||||
Strona ``https://api.fixer.io/latest`` udostępnia kursy różnych walut w stosunku do euro. Napisz skrypt, który:
|
||||
* pobierze zawartość JSONa. Wykorzystaj bibliotekę ``requests`` (http://docs.python-requests.org/en/master/).
|
||||
* korzystając z biblioteki ``json`` przekształć go do obiketu typu JSON.
|
||||
* Wyświetl wartość kursu EUR do PLN.
|
||||
"""
|
||||
|
||||
import requests
|
||||
import json
|
||||
|
||||
rawData = requests.get('https://api.fixer.io/latest')
|
||||
|
||||
# Program dlugo sie uruchamia
|
||||
pln = json.loads(rawData.text).get("rates").get("PLN")
|
||||
print pln
|
37
labs03/task04.py
Normal file
37
labs03/task04.py
Normal file
@ -0,0 +1,37 @@
|
||||
# coding=utf-8
|
||||
"""
|
||||
**ćwiczenie 4**
|
||||
Zainstaluj bibliotekę ``weather-api`` (https://pypi.python.org/pypi/weather-api). Korzystając z niej:
|
||||
* Wypisz informacje o aktualnej pogodzie.
|
||||
* Napisz funkcję, która zamieni stopnie ``F`` na ``C``.
|
||||
* Korzystając z prognozy, znajdź dzień, w którym będzie najzimniej. Wypisz nazwę tygodnia (w języku polskim) i temperaturę w C.
|
||||
"""
|
||||
|
||||
from weather import Weather
|
||||
from operator import itemgetter
|
||||
from datetime import datetime
|
||||
|
||||
def FhCs(x):
|
||||
x = float(x)
|
||||
cs = (x - 32)/1.8
|
||||
return round(cs, 1)
|
||||
|
||||
userInput = raw_input('Please type a city name: ')
|
||||
|
||||
weather = Weather()
|
||||
city = weather.lookup_by_location(userInput)
|
||||
cityNow = city.condition()
|
||||
cityNowText = cityNow.text()
|
||||
cityNowTemp = cityNow.temp()
|
||||
cityCelsius = FhCs(cityNowTemp)
|
||||
|
||||
print 'Current weather: ', cityNowText, ', ', cityCelsius, '°C'
|
||||
|
||||
cityForecasts = city.forecast()
|
||||
|
||||
x = {forecast.date() : forecast.low() for forecast in cityForecasts}
|
||||
y = min(x.iteritems(), key=itemgetter(1))
|
||||
|
||||
date = datetime.strptime(y[0], "%d %b %Y")
|
||||
minCels = FhCs(y[1])
|
||||
print date.strftime("%A"), minCels
|
31
labs03/task05.py
Normal file
31
labs03/task05.py
Normal file
@ -0,0 +1,31 @@
|
||||
# coding=utf-8
|
||||
"""
|
||||
**ćwiczenie 5**
|
||||
Katalog scores zawiera 64 pliki tekstowe, które posiadają informacje o wysokości miary ``BLEU`` na różnych etapach trenowania modelu. Nazwa każdego pliku na postać ``model.iterXXXXXXX.npz.bleu``, gdzie ``XXXXXXX``, to liczba iteracji.Zawartość każdego pliku jest podobna i ma następującą formę: *BLEU = YY.YY, 44.4/18.5/9.3/5.0 (BP=1.000, ratio=1.072, hyp_len=45976, ref_len=42903)*, gdzie ``YY.YY`` to wartość miary ``BLEU``. Znajdź plik, który zawiera najwyższą wartość miary ``BLEU``.
|
||||
* Wykorzystaj bibliotekę ``glob`` (https://docs.python.org/2/library/glob.html)
|
||||
* Wyświetl tylko pełną nazwe pliku (wraz z ścieżką).
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
x = 0
|
||||
|
||||
#print os.listdir('.\scores')
|
||||
cwd = os.getcwd()
|
||||
os.chdir(cwd+'/scores')
|
||||
|
||||
maxBleu = {}
|
||||
|
||||
for f in os.listdir('.'):
|
||||
with open(f, 'r') as plik:
|
||||
for line in plik:
|
||||
lineSplit = line.split()
|
||||
maxValue = float(lineSplit[2].replace(',',''))
|
||||
if not maxBleu:
|
||||
maxBleu[f] = maxValue
|
||||
else:
|
||||
if maxValue > maxBleu.values()[0]:
|
||||
maxBleu.clear()
|
||||
maxBleu[f] = maxValue
|
||||
|
||||
print maxBleu
|
@ -1,3 +1,11 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
def is_numeric(x):
|
||||
if all(isinstance(i, (int, float)) for i in x):
|
||||
print 'All elements in the list are integers or floats'
|
||||
return True
|
||||
else:
|
||||
print 'NOT all elements in the list are integers or floats'
|
||||
return False
|
||||
|
@ -1,3 +1,33 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: utf-8 -*-
|
||||
import time
|
||||
|
||||
class Employee:
|
||||
id = int(time.time())
|
||||
|
||||
def __init__(self, name, surname):
|
||||
self.name = name
|
||||
self.surname = surname
|
||||
|
||||
def get_id(self):
|
||||
return self.id
|
||||
|
||||
# Check the first class
|
||||
x = Employee('Mateusz', 'Kowalski')
|
||||
print x.get_id()
|
||||
|
||||
# Second class
|
||||
class Recruiter(Employee):
|
||||
recruited = []
|
||||
def recruit(self):
|
||||
self.recruited.append(self.get_id())
|
||||
|
||||
# Check the second class
|
||||
y = Recruiter('Mateusz', 'Kowalski')
|
||||
y.recruit()
|
||||
print y.recruited
|
||||
|
||||
# Third class
|
||||
class Programmer(Recruiter):
|
||||
def recruiter(self):
|
||||
self.recruiter = self.get_id()
|
||||
|
@ -1,3 +1,46 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import task01
|
||||
|
||||
class DimensionError(Exception):
|
||||
pass
|
||||
|
||||
class Point:
|
||||
pointList = []
|
||||
|
||||
def __init__(self, coord):
|
||||
if isinstance(coord, list):
|
||||
if task01.is_numeric(coord):
|
||||
self.coord = coord
|
||||
self.x = coord[0]
|
||||
self.y = coord[1]
|
||||
if len(coord) == 3:
|
||||
self.z = coord[2]
|
||||
|
||||
self.pointList.append(self.coord)
|
||||
|
||||
else:
|
||||
print 'NOT all elements in the list are integers or floats'
|
||||
else:
|
||||
raise DimensionError('The argument must be a list')
|
||||
|
||||
def add(self, point1, point2):
|
||||
point3 = []
|
||||
|
||||
if isinstance(point1, Point) and isinstance(point2, Point):
|
||||
point3.append(point1.x + point2.x)
|
||||
point3.append(point1.y + point2.y)
|
||||
point3.append(point1.z + point2.z)
|
||||
return Point(point3)
|
||||
else:
|
||||
print 'Arguments must be Points'
|
||||
|
||||
def __len__(self):
|
||||
return len(self.coord)
|
||||
|
||||
def to_string(self):
|
||||
return 'Point coordinates: x: {0} y: {1} z: {2}'.format(self.x, self.y, self.z)
|
||||
|
||||
def __str__(self):
|
||||
print self.to_string()
|
||||
|
@ -2,10 +2,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
def suma(liczby):
|
||||
pass
|
||||
liczby = [float(i) for i in liczby]
|
||||
return sum(liczby)
|
||||
|
||||
def main():
|
||||
print(summa([1, 2, 3, 4]))
|
||||
print(suma([1, 2, 3, 4]))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
@ -0,0 +1,10 @@
|
||||
from task00 import suma
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
x = sys.argv[1:]
|
||||
print(suma(x))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -0,0 +1,17 @@
|
||||
from task00 import suma
|
||||
import sys
|
||||
|
||||
def main():
|
||||
listToSum = sys.argv[1:]
|
||||
|
||||
for i in listToSum:
|
||||
x = listToSum.index(i)
|
||||
try:
|
||||
float(i)
|
||||
except:
|
||||
listToSum[x] = 0
|
||||
|
||||
print(suma(listToSum))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -0,0 +1,12 @@
|
||||
from task00 import suma
|
||||
import argparse
|
||||
|
||||
def main():
|
||||
parse = argparse.ArgumentParser()
|
||||
parse.add_argument("float", help="floating numbers", nargs = '+')
|
||||
arguments = parse.parse_args()
|
||||
result = arguments.float
|
||||
print(suma(result))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -7,6 +7,7 @@ Zwraca liczbę słów, znaków i linii.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
|
||||
def count_lines(text):
|
||||
@ -34,6 +35,28 @@ def main():
|
||||
""" main """
|
||||
print(wc(sys.stdin.read()))
|
||||
|
||||
parse = argparse.ArgumentParser()
|
||||
parse.add_argument('--l', help = 'number of lines', action = 'store_true')
|
||||
parse.add_argument('--w', help = 'number of words', action = 'store_true')
|
||||
parse.add_argument('--c', help = 'number of characters', action = 'store_true')
|
||||
parse.add_argument('file', help = 'filepath', type = argparse.FileType('f'), nargs = '?')
|
||||
args = parse.parse_args()
|
||||
|
||||
if args.file is None:
|
||||
opt = sys.stdin.read()
|
||||
else:
|
||||
opt = args.file.read()
|
||||
|
||||
if args.l:
|
||||
output = count_lines(opt)
|
||||
elif args.w:
|
||||
output = count_words(opt)
|
||||
elif args.c:
|
||||
output = count_chars(opt)
|
||||
else:
|
||||
output = wc(opt)
|
||||
|
||||
print(output)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
@ -1,14 +1,25 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import pandas as pd
|
||||
|
||||
def wczytaj_dane():
|
||||
pass
|
||||
|
||||
mieszkania = pd.read_csv('C:\Users\mlyska\Documents\python2017\labs06\mieszkania.csv', sep = ',')
|
||||
mieszkania.fillna('', inplace=True)
|
||||
mieszkania['Description'] = mieszkania['Description'] + mieszkania['Unnamed: 7'] + mieszkania['Unnamed: 8'] + \
|
||||
mieszkania['Unnamed: 9'] + mieszkania['Unnamed: 10'] + mieszkania['Unnamed: 11']
|
||||
mieszkania.drop(['Unnamed: 7','Unnamed: 8','Unnamed: 9','Unnamed: 10','Unnamed: 11'], 1, inplace=True)
|
||||
return mieszkania
|
||||
|
||||
def most_common_room_number(dane):
|
||||
pass
|
||||
counter = dane['Rooms'].value_counts()
|
||||
maxCount = counter.to_frame()
|
||||
return maxCount.index.values[0]
|
||||
|
||||
def cheapest_flats(dane, n):
|
||||
pass
|
||||
dane.sort_values('Expected')
|
||||
return dane.head(n)
|
||||
|
||||
def find_borough(desc):
|
||||
dzielnice = ['Stare Miasto',
|
||||
@ -19,23 +30,46 @@ def find_borough(desc):
|
||||
'Winogrady',
|
||||
'Miłostowo',
|
||||
'Dębiec']
|
||||
pass
|
||||
|
||||
for i in dzielnice:
|
||||
if i in desc:
|
||||
return i
|
||||
break
|
||||
if desc not in dzielnice:
|
||||
return 'Inne'
|
||||
|
||||
|
||||
|
||||
def add_borough(dane):
|
||||
pass
|
||||
values = []
|
||||
for i in dane['Location']:
|
||||
values.append(find_borough(i))
|
||||
|
||||
tempSeries = pd.Series(values)
|
||||
dane['Borough'] = tempSeries.values
|
||||
|
||||
def write_plot(dane, filename):
|
||||
pass
|
||||
add_borough(dane)
|
||||
dataPlot = dane['Borough'].value_counts()
|
||||
|
||||
imgPlot = dataPlot.plot(kind='bar', alpha=0.5, title='Liczba ogloszen mieszkan z podzialem na dzielnice', fontsize=6, figsize=(8,7))
|
||||
imgPlot.set_ylabel('Liczba ogloszen')
|
||||
imgPlot.set_xlabel('Dzielnice')
|
||||
|
||||
filePlot = imgPlot.get_figure()
|
||||
filePlot.savefig(filename)
|
||||
|
||||
def mean_price(dane, room_number):
|
||||
pass
|
||||
x = dane.loc[dane['Rooms'] == room_number]
|
||||
return x['Expected'].mean()
|
||||
|
||||
def find_13(dane):
|
||||
pass
|
||||
x = dane.loc[dane['Floor'] == 13]
|
||||
return list(set(x['Borough'].tolist()))
|
||||
|
||||
def find_best_flats(dane):
|
||||
pass
|
||||
best = dane.loc[dane['Borough'] == 'Winogrady' & dane['Rooms'] == 3 & dane['Floor'] == 1]
|
||||
return best
|
||||
|
||||
def main():
|
||||
dane = wczytaj_dane()
|
||||
@ -45,10 +79,12 @@ def main():
|
||||
.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)))
|
||||
|
||||
write_plot(dane, 'ogloszenia.png')
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user