Compare commits

...

10 Commits

21 changed files with 210 additions and 21 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,15 @@
Napisz funkcję days_in_year zwracającą liczbę dni w roku (365 albo 366).
"""
def days_in_year(days):
pass
def days_in_year(year):
if year % 4 == 0 and year % 100 == 0 and year % 400 == 0:
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):
inputs = [[2015], [2012], [1900], [2400], [1977]]

View File

@ -13,7 +13,11 @@ jak 'set', która przechowuje elementy bez powtórzeń.)
def oov(text, vocab):
pass
s=set()
for i in text.split():
if i not in vocab:
s.add(i)
return s

View File

@ -7,7 +7,14 @@ 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:
x=0
for i in range (n+1):
x=x+i
return x
def tests(f):

View File

@ -9,8 +9,11 @@ trzyelementowe listy liczb zmiennoprzecinkowych.
np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5.
"""
def euclidean_distance(x, y):
pass
dist=((x[0]-y[0])**2+(x[1]-y[1])**2+(x[2]-y[2])**2)**(1/2)
return dist
def tests(f):
inputs = [[(2.3, 4.3, -7.5), (2.3, 8.5, -7.5)]]

View File

@ -10,7 +10,14 @@ 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:
tekst="N"
for i in range (n):
tekst += "O"
tekst += "!"
return(tekst)
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 i in range (len(text)):
suma+=ord(text[i])
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,7 +9,7 @@ Np. leet('leet') powinno zwrócić '1337'.
def leet_speak(text):
pass
return(text.replace("e","3").replace("l", "1").replace("o", "0").replace("t", "7"))
def tests(f):

View File

@ -9,7 +9,14 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
def pokemon_speak(text):
pass
for i in range(len(text)):
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):
@ -23,4 +30,4 @@ def tests(f):
return "TESTS PASSED"
if __name__ == "__main__":
print(tests(pokemon_speak))
print(tests(pokemon_speak))

View File

@ -9,7 +9,14 @@ Oba napisy będą składać się wyłacznie z małych liter.
"""
def common_chars(string1, string2):
pass
s=[]
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):

View File

@ -1 +0,0 @@
BLEU = 17.66, 49.6/22.6/12.3/7.0 (BP=1.000, ratio=1.019, hyp_len=43697, ref_len=42903)

8
labs03/task01.py Normal file
View File

@ -0,0 +1,8 @@
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))

0
labs03/task02.py Normal file
View File

0
labs03/task03.py Normal file
View File

16
labs03/task05.py Normal file
View File

@ -0,0 +1,16 @@
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)

View File

@ -309,13 +309,13 @@
{
"ename": "AttributeError",
"evalue": "'Parser' object has no attribute '__parse'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\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;31mAttributeError\u001b[0m: 'Parser' object has no attribute '__parse'"
]
],
"output_type": "error"
}
],
"source": [
@ -465,13 +465,13 @@
{
"ename": "FileNotFoundError",
"evalue": "[Errno 2] No such file or directory: 'nieistniejący_plik.txt'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\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;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'nieistniejący_plik.txt'"
]
],
"output_type": "error"
}
],
"source": [
@ -614,13 +614,13 @@
{
"ename": "MyError",
"evalue": "Coś poszło nie tak!",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\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;31mMyError\u001b[0m: Coś poszło nie tak!"
]
],
"output_type": "error"
}
],
"source": [

View File

@ -1,3 +1,10 @@
#!/usr/bin/env python2
# -*- 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])

View File

@ -1,3 +1,8 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
class Employee:
def __init__(self, imie, nazwisko):
def get_id():
return(id)

View File

@ -1,3 +1,56 @@
#!/usr/bin/env python2
# -*- 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)

View File

@ -1,15 +1,36 @@
#!/usr/bin/env python
# -*- 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():
dane = pd.read_csv('mieszkania.csv', sep=',')
dane.rename(columns={'Unnamed: 11': 'Borough'}, inplace=True)
#type(dane)
#print(dane.head())
return(dane)
pass
def most_common_room_number(dane):
m = dane.groupby(['Rooms']).count()
return(m['Id'].idxmax())
pass
def cheapest_flats(dane, n):
dane2 = dane.sort_values(by=['Expected'])
return(dane2.head(n))
pass
def find_borough(desc):
dzielnice = ['Stare Miasto',
'Wilda',
@ -19,24 +40,54 @@ def find_borough(desc):
'Winogrady',
'Miłostowo',
'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
def add_borough(dane):
for i in range(5000):#len(dane.axes[0])):
dane['Borough'][i] = find_borough(dane['Location'][i])
pass
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
def mean_price(dane, room_number):
m = dane.groupby(['Rooms']).mean()
return(m['Expected'][room_number])
pass
def find_13(dane):
df_filtered = dane[dane['Floor'] == 13]
return(df_filtered['Borough'])
pass
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
def main():
dane = wczytaj_dane()
print(dane[:5])
@ -45,7 +96,7 @@ 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)))