Compare commits

...

8 Commits

Author SHA1 Message Date
Magda Zganiacz
56f654961c zadanie domowe 2018-06-22 15:59:02 +02:00
Magda Zganiacz
7f64a03469 zadanie domowe 2018-06-21 19:28:33 +02:00
Magda Zganiacz
adf2d4d587 Merge branch 'master' of https://git.wmi.amu.edu.pl/tdwojak/Python2018 2018-06-04 19:57:36 +02:00
Magda Zganiacz
02e9da89d2 Zadanie domowe 2018-06-02 19:46:40 +02:00
Magda Zganiacz
c4cf32a7f8 Zadanie domowe 2018-06-02 19:40:33 +02:00
s352037
6c10fb4b03 zrobione na zajeciach 2018-05-13 12:45:02 +02:00
s352037
9938591fa6 zrobione na zajeciach 2018-05-13 10:55:34 +02:00
s352037
ad77edc363 test_task 2018-05-13 08:44:46 +02:00
16 changed files with 128 additions and 38 deletions

View File

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

View File

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

View File

@ -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):

View File

@ -6,7 +6,9 @@
""" """
def days_in_year(days): def days_in_year(days):
pass if days%4 == 0 and days%100 != 0 or days%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]]

View File

@ -13,7 +13,10 @@ jak 'set', która przechowuje elementy bez powtórzeń.)
def oov(text, vocab): def oov(text, vocab):
pass test = text.split(' ')
a = set(test)
b = set(vocab)
return a - b

View File

@ -7,9 +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):
if n > 1:
wynik = 0
for i in range(n+1):
wynik += i
return wynik
else: return 0
pass pass
def tests(f): def tests(f):
inputs = [[999], [-100]] inputs = [[999], [-100]]
outputs = [499500, 0] outputs = [499500, 0]

View File

@ -10,7 +10,11 @@ np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5.
""" """
def euclidean_distance(x, y): def euclidean_distance(x, y):
pass sum = 0
for i in range(len(x)):
sum += ((x[i]-y[i])**2)
distance = sum ** (1/2)
return distance
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)]]

View File

@ -10,7 +10,11 @@ ma być zwracany napis "It's not a Big 'No!'".
""" """
def big_no(n): def big_no(n):
pass string = "NO!"
if n >= 5:
napis = string[0]+string[1]*n+string[2]
return napis
else: return "It's not a Big 'No!'"
def tests(f): def tests(f):
inputs = [[5], [6], [2]] 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. sumę kodów ASCII znaków.
""" """
def char_sum(text): def char_sum(text):
pass sum = 0
for x in text:
sum += ord(x)
return sum
def tests(f): def tests(f):
inputs = [["this is a string"], ["this is another string"]] inputs = [["this is a string"], ["this is another string"]]

View File

@ -7,7 +7,11 @@ przez 3 lub 5 mniejszych niż n.
""" """
def sum_div35(n): def sum_div35(n):
pass sum = 0
for i in range(n):
if i%3 == 0 or i%5 == 0:
sum += i
return sum
def tests(f): def tests(f):
inputs = [[10], [100], [3845]] inputs = [[10], [100], [3845]]

View File

@ -9,8 +9,13 @@ 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'}
napis = ''
for i in text:
if i in slownik:
napis += slownik[i]
else: napis += i
return napis
def tests(f): def tests(f):
inputs = [['leet'], ['do not want']] inputs = [['leet'], ['do not want']]

View File

@ -9,7 +9,15 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
def pokemon_speak(text): def pokemon_speak(text):
pass a = 0
napis = ''
for i in text:
a += 1
if a%2 == 1:
i = i.upper()
else: i
napis += i
return napis
def tests(f): def tests(f):

View File

@ -9,7 +9,15 @@ Oba napisy będą składać się wyłacznie z małych liter.
""" """
def common_chars(string1, string2): def common_chars(string1, string2):
pass lista = []
str1 = set(string1.replace(' ', ''))
str2 = set(string2.replace(' ', ''))
for i in str1:
for j in str2:
if i == j:
lista.append(i)
lista.sort()
return lista
def tests(f): def tests(f):

View File

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

16
labs04/05.py Normal file
View File

@ -0,0 +1,16 @@
import glob
import os
max_wartosc_bleu = 0
max_nazwa_pliku =''
for nazwa_pliku in glob.glob('scores/*'):
with open(nazwa_pliku, 'r') as plik:
for linia in plik.readlines():
wartosc_bleu = linia.split(' ')[2]
wartosc_bleu = float(wartosc_bleu.strip(','))
if wartosc_bleu > max_wartosc_bleu:
max_wartosc_bleu = wartosc_bleu
max_nazwa_pliku = nazwa_pliku
print(max_nazwa_pliku)

View File

@ -1,14 +1,19 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import pandas as pd
from statistics import mode
import matplotlib.pyplot as plt
def wczytaj_dane(): def wczytaj_dane():
pass r = pd.read_csv("mieszkania.csv")
dane = r.dropna(axis='columns')
return dane
def most_common_room_number(dane): def most_common_room_number(dane):
pass return mode(dane.Rooms)
def cheapest_flats(dane, n): def cheapest_flats(dane, n):
pass return dane.sort_values(by="Expected").head(n)
def find_borough(desc): def find_borough(desc):
dzielnice = ['Stare Miasto', dzielnice = ['Stare Miasto',
@ -19,23 +24,36 @@ def find_borough(desc):
'Winogrady', 'Winogrady',
'Miłostowo', 'Miłostowo',
'Dębiec'] 'Dębiec']
pass
indeks = len(desc)
nazwa_dzielnicy = "Inne"
for dzielnica in dzielnice:
indeks_dzielnica = desc.find(dzielnica)
if indeks_dzielnica < indeks and indeks_dzielnica != -1:
indeks = indeks_dzielnica
nazwa_dzielnicy = dzielnica
return nazwa_dzielnicy
def add_borough(dane): def add_borough(dane):
pass dane['Borough'] = dane['Location'].apply(find_borough)
return dane
def write_plot(dane, filename): def write_plot(dane, filename):
pass add_borough(dane)
dane_wykres = pd.Series(dane.Borough.value_counts())
dane_wykres.plot(x='Borough', y='Liczba ogłoszeń', kind = 'bar')
plt.savefig(filename, pad_inches=1, bbox_inches='tight')
def mean_price(dane, room_number): def mean_price(dane, room_number):
pass return dane.Expected[(dane['Rooms'] == room_number)].mean()
def find_13(dane): def find_13(dane):
pass add_borough(dane)
return dane.Borough[(dane['Floor'] == 13)].unique()
def find_best_flats(dane): def find_best_flats(dane):
pass add_borough(dane)
return dane[(dane['Borough'] == 'Winogrady') & (dane['Rooms'] == 3) & (dane['Floor'] == 1)]
def main(): def main():
dane = wczytaj_dane() dane = wczytaj_dane()
@ -44,8 +62,8 @@ def main():
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ładniejsza 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)))