Compare commits

...

9 Commits

Author SHA1 Message Date
Adam 3f1dc2ab7a homework 2018-06-23 13:25:32 +02:00
Adam 2e987de4d5 Merge https://git.wmi.amu.edu.pl/tdwojak/Python2018 2018-06-23 12:21:27 +02:00
s441403 c0a7d2aed1 Merge remote-tracking branch 'origin/master' 2018-06-02 13:55:38 +02:00
s441403 2e6ea30105 zadanie 5 z lab04 zrobiono 2018-06-02 13:54:48 +02:00
Adam 489e0e84cc all done 2018-05-15 22:47:14 +02:00
s441403 d6f4abe562 task 05-10 2018-05-13 12:54:21 +02:00
s441403 bfde5771a7 task 01-04 2018-05-13 10:04:52 +02:00
s441403 dd9587b180 task 01-04 2018-05-13 10:04:45 +02:00
s441403 e53fc85078 test_task done 2018-05-13 08:46:56 +02:00
16 changed files with 142 additions and 35 deletions

View File

@ -168,7 +168,7 @@ for i in range(5):# range[5] = [0,1,2,3,4]
for zmienna in lista:
# operacje do wykonania w pętli
pass
# In[ ]:

View File

@ -9,48 +9,52 @@ Zadania wprowadzające do pierwszych ćwiczeń.
"""
Wypisz na ekran swoje imię i nazwisko.
"""
print("Adam Kisiel")
"""
Oblicz i wypisz na ekran pole koła o promienie 10. Jako PI przyjmij 3.14.
"""
pole = 3.14 * (10 ** 2)
print(pole)
"""
Stwórz zmienną pole_kwadratu i przypisz do liczbę: pole kwadratu o boku 3.
"""
pole_kwadratu = 3 * 3
"""
Stwórz 3 elementową listę, która zawiera nazwy 3 Twoich ulubionych owoców.
Wynik przypisz do zmiennej `owoce`.
"""
owoce = ['jabłko', 'pomarańcza', 'gruszka']
"""
Dodaj do powyższej listy jako nowy element "pomidor".
"""
owoce.append('pomidor')
"""
Usuń z powyższej listy drugi element.
"""
owoce.pop(1)
"""
Rozszerz listę o tablice ['Jabłko', "Gruszka"].
"""
owoce.extend(['Jabłko', 'Gruszka'])
"""
Wyświetl listę owoce, ale bez pierwszego i ostatniego elementu.
"""
print(owoce[0:-2])
"""
Wyświetl co trzeci element z listy owoce.
"""
print(owoce[::3])
"""
Stwórz pusty słownik i przypisz go do zmiennej magazyn.
"""
magazyn = {}
"""
Dodaj do słownika magazyn owoce z listy owoce, tak, aby owoce były kluczami,
zaś wartościami były równe 5.
"""
for key in owoce:
magazyn[key] = [5]
print(magazyn)

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

@ -6,8 +6,12 @@
"""
def days_in_year(days):
pass
liczba_dni = 0
if days % 4 == 0 and days % 100 != 0 or days % 400 == 0:
liczba_dni = 366
else:
liczba_dni = 365
return liczba_dni
def tests(f):
inputs = [[2015], [2012], [1900], [2400], [1977]]
outputs = [365, 366, 365, 366, 365]

View File

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

View File

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

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import math
"""
Napisz funkcję euclidean_distance obliczającą odległość między
dwoma punktami przestrzeni trójwymiarowej. Punkty dane jako
@ -10,7 +10,12 @@ np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5.
"""
def euclidean_distance(x, y):
pass
counter = 0
for i in range(len(x)):
d= math.pow(x[i] - y[i],2)
counter += d
distance = math.sqrt(counter)
return distance
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
if n < 5:
return "It's not a Big 'No!'"
else:
big_no = "N" + "O" * n + "!"
return big_no
def tests(f):
inputs = [[5], [6], [2]]

View File

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

View File

@ -7,7 +7,14 @@ 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,17 @@ Np. leet('leet') powinno zwrócić '1337'.
def leet_speak(text):
pass
lista = list(text)
słownik = {'1':'l', '3':'e', '0':'o', '7':'t'}
lista_wartosci = słownik.values()
lista_mod = []
for i in range(len(lista)):
for key, value in słownik.items():
if lista[i] in value:
lista[i]=key
wynik = "".join(lista)
return wynik
def tests(f):

View File

@ -9,7 +9,17 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
def pokemon_speak(text):
pass
lista = list(text)
result = []
for i in range(len(lista)):
if i == 0 or i % 2 == 0:
result.append(lista[i].upper())
else:
result.append(lista[i])
wynik = "".join(result)
return wynik
def tests(f):

View File

@ -9,7 +9,16 @@ Oba napisy będą składać się wyłacznie z małych liter.
"""
def common_chars(string1, string2):
pass
string1 = string1.replace(' ','')
string2 = string2.replace(' ','')
lista1 = list(string1)
lista2 = list(string2)
wynik = set()
wynik = {x for x in lista1 if x in lista2}
result = list(wynik)
result.sort()
return result
def tests(f):

View File

@ -6,7 +6,8 @@ def suma(a, b):
"""
Napisz funkcję, która zwraca sumę elementów.
"""
return 0
wynik = a + b
return wynik
def tests(f):
inputs = [(2, 3), (0, 0), (1, 1)]

23
labs04/Zadanie5.py Normal file
View File

@ -0,0 +1,23 @@
import glob
pliki = glob.glob('scores/*')
wyniki = []
for plik in pliki:
f = open(plik, 'r')
linia = f.readline()
linia = linia.split(" ")
#print(linia)
linia = [x.strip(",") for x in linia]
wyniki.append(linia[2])
f.close()
max_index = wyniki.index(max(wyniki))
#print(wyniki)
#print(max_index)
max_value = wyniki[max_index]
plik_z_maxBLEU = pliki[max_index]
print(plik_z_maxBLEU)

View File

@ -1,14 +1,20 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pandas as pd
from statistics import mode
import matplotlib.pyplot as plt
def wczytaj_dane():
pass
data = pd.read_csv('mieszkania.csv')
return data
def most_common_room_number(dane):
pass
return mode(dane.Rooms)
def cheapest_flats(dane, n):
pass
sorted = dane.Expected.sort()
return sorted.head(n)
def find_borough(desc):
dzielnice = ['Stare Miasto',
@ -19,23 +25,35 @@ def find_borough(desc):
'Winogrady',
'Miłostowo',
'Dębiec']
pass
for dzielnica in dzielnice:
list = desc.split(' ')
for element in list:
if len(element) > 2 and element == dzielnica:
return dzielnica
break
return "Inne"
def add_borough(dane):
pass
dane['Borough'] = dane['Location'].apply(find_borough)
return dane
def write_plot(dane, filename):
pass
plotdata = pd.Series(dane.Location.value_counts())
plotdata.plot(x='Location', y='Liczba ogłoszeń', kind='bar')
plt.savefig(filename)
def mean_price(dane, room_number):
pass
mean_price = dane.Expected[(dane['Rooms'] == room_number)]
return mean_price.mean()
def find_13(dane):
pass
return dane.Location[(dane['Floor'] == 13)].unique()
def find_best_flats(dane):
pass
return dane[(dane['Location'] == 'Winogrady') & (dane['Rooms'] == 3) & (dane['Floor'] == 1)]
def main():
dane = wczytaj_dane()
@ -45,7 +63,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)))