1
0
forked from tdwojak/Python2018

Compare commits

..

No commits in common. "master" and "master" have entirely different histories.

21 changed files with 60 additions and 165 deletions

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.6.5 (C:\software\python3\python3.exe)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6.5 (C:\software\python3\python3.exe)" project-jdk-type="Python SDK" />
</project>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Python2018.iml" filepath="$PROJECT_DIR$/.idea/Python2018.iml" />
</modules>
</component>
</project>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

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,59 +9,48 @@ Zadania wprowadzające do pierwszych ćwiczeń.
"""
Wypisz na ekran swoje imię i nazwisko.
"""
print ('monika', 'budzyńska')
"""
Oblicz i wypisz na ekran pole koła o promienie 10. Jako PI przyjmij 3.14.
"""
pi = 3.14
R = 10
pole = pi * (R ** 2)
print ('pole koła =', 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`.
"""
lista_owoców = ['awokado', 'jabłko', 'kiwi']
owoce = lista_owoców
print (owoce)
"""
Dodaj do powyższej listy jako nowy element "pomidor".
"""
lista_owoców.append('pomidor')
print (owoce)
"""
Usuń z powyższej listy drugi element.
"""
lista_owoców.pop(1)
print(owoce)
"""
Rozszerz listę o tablice ['Jabłko', "Gruszka"].
"""
lista_owoców.extend(['jabłko','gruszka'])
print(owoce)
"""
Wyświetl listę owoce, ale bez pierwszego i ostatniego elementu.
"""
print(owoce[1:4])
""""
"""
Wyświetl co trzeci element z listy owoce.
"""
print(owoce[2::3])
"""
Stwórz pusty słownik i przypisz go do zmiennej magazyn.
"""
slownik = {}
magazyn = slownik
"""
Dodaj do słownika magazyn owoce z listy owoce, tak, aby owoce były kluczami,
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):
return lista[::2]
pass
def tests(f):

View File

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

View File

@ -9,18 +9,13 @@ znanych wyrazów vocab. Argumenty funkcji text i vocab to odpowiednio łańcuch
znakowy i lista łańuchów znakowych. Wszystkie wyrazy należy zmienić na małe
litery. (OOV = out of vocabulary) (W pythonie istnieje struktura danych tak
jak 'set', która przechowuje elementy bez powtórzeń.)
text - łańcuch znakowy
vocab - lista łańcuchów znakowych
"""
def oov(text, vocab):
b = set()
a = text.split (" ")
for abc in a:
if abc not in vocab:
b.add(abc)
return b
pass
def tests(f):
inputs = [("this is a string , which i will use for string testing",

View File

@ -7,10 +7,8 @@ Jeśli podany argument jest mniejszy od 1 powinna być zwracana wartość 0.
"""
def sum_from_one_to_n(n):
if n < 1:
return 0
else:
return sum(range(n+1))
pass
def tests(f):
inputs = [[999], [-100]]

View File

@ -7,15 +7,10 @@ Napisz funkcję euclidean_distance obliczającą odległość między
dwoma punktami przestrzeni trójwymiarowej. Punkty dane jako
trzyelementowe listy liczb zmiennoprzecinkowych.
np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5.
x = [0, 0, 0]
y = [3, 4, 0]
"""
def euclidean_distance(x, y):
if len(x) != len(y):
return 0
else:
return ((x[0] - y[0])**2 + (x[1]-y[1])**2 + (x[2]-y[2])**2)**0.5
pass
def tests(f):
inputs = [[(2.3, 4.3, -7.5), (2.3, 8.5, -7.5)]]

View File

@ -10,12 +10,7 @@ ma być zwracany napis "It's not a Big 'No!'".
"""
def big_no(n):
pierwsze_n = "N"
if n < 5:
return "It's not a Big 'No!'"
else:
return pierwsze_n + n*"O" + "!"
pass
def tests(f):
inputs = [[5], [6], [2]]

View File

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

View File

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

View File

@ -9,11 +9,7 @@ Np. leet('leet') powinno zwrócić '1337'.
def leet_speak(text):
text = text.replace('e', '3')
text = text.replace('l', '1')
text = text.replace('o', '0')
text = text.replace('t', '7')
return text
pass
def tests(f):

View File

@ -9,15 +9,7 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
def pokemon_speak(text):
new_text = ''
capitalize = True
for x in text:
if capitalize is True:
new_text += x.upper()
else:
new_text += x
capitalize = not capitalize
return new_text
pass
def tests(f):

View File

@ -9,17 +9,7 @@ Oba napisy będą składać się wyłacznie z małych liter.
"""
def common_chars(string1, string2):
wspolne = []
string1 = string1.replace(' ', '')
string2 = string2.replace(' ', '')
znaki_z_1 = set(string1)
znaki_z_2 = set(string2)
for x in znaki_z_1:
if x in znaki_z_2:
wspolne.append(x)
return sorted(wspolne)
pass
def tests(f):

View File

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

View File

@ -232,13 +232,13 @@
{
"ename": "TypeError",
"evalue": "unhashable type: 'list'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-25-2bd2fa17fbf5>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m{\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m: unhashable type: 'list'"
],
"output_type": "error"
]
}
],
"source": [
@ -398,13 +398,13 @@
{
"ename": "ValueError",
"evalue": "I/O operation on closed file.",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-47-f06513c1bbec>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mlinia\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mplik\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreadlines\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[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlinia\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \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[0m",
"\u001b[0;31mValueError\u001b[0m: I/O operation on closed file."
],
"output_type": "error"
]
}
],
"source": [

View File

@ -1,18 +1,14 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pandas as pd
import matplotlib.pyplot as plt
def wczytaj_dane():
dane = pd.read_csv("mieszkania.csv")
dane.head()
pass
def most_common_room_number(dane):
return(dane['Rooms'].value_counts().idxmax())
pass
def cheapest_flats(dane, n):
p = dane.sort_values(['Expected'], ascending=[0])
p.head(n)
pass
def find_borough(desc):
dzielnice = ['Stare Miasto',
@ -23,28 +19,23 @@ def find_borough(desc):
'Winogrady',
'Miłostowo',
'Dębiec']
for i in dzielnice:
if desc.find(i) + 1:
return (i)
return ('Inne')
pass
def add_borough(dane):
dane['Borough'] = dane['Location'].apply(find_borough)
return (dane)
pass
def write_plot(dane, filename):
dane['Borough'].hist()
plt.savefig(filename)
pass
def mean_price(dane, room_number):
return dane.Expected[dane.Rooms == room_number].mean()
pass
def find_13(dane):
return dane.Borough[dane.Floor == 13].unique()
pass
def find_best_flats(dane):
return dane[(dane.Borough == 'Winogrady') & (dane.Rooms == 3) & (dane.Floor == 1)]
pass
def main():
dane = wczytaj_dane()

View File

@ -4,61 +4,62 @@
"""
1. Zaimportuj bibliotkę pandas jako pd.
"""
import pandas as pd
"""
2. Wczytaj zbiór danych `311.csv` do zmiennej data.
2. Wczytaj zbiór danych `311.csv` do zniennej data.
"""
data = pd.read_csv("./311.csv")
"""
3. Wyświetl 5 pierwszych wierszy z data.
"""
print(data.head(5))
"""
4. Wyświetl nazwy kolumn.
"""
#print(data.columns)
"""
5. Wyświetl ile nasz zbiór danych ma kolumn i wierszy.
"""
shape = data.shape
rows = shape[0]
cols = shape[1]
#print(rows, cols)
"""
6. Wyświetl kolumnę 'City' z powyższego zbioru danych.
"""
#print(data.City)
"""
7. Wyświetl jakie wartoścu przyjmuje kolumna 'City'.
"""
#print(data.City.unique())
"""
8. Wyświetl tabelę rozstawną kolumny City (zliczanie wartosci) value_counts.
8. Wyświetl tabelę rozstawną kolumny City.
"""
#print(data.City.value_counts())
"""
9. Wyświetl tylko pierwsze 4 wiersze z wcześniejszego polecenia.
"""
#print(data.City.value_counts().head(4))
"""
10. Wyświetl, w ilu przypadkach kolumna City zawiera NaN
10. Wyświetl, w ilu przypadkach kolumna City zawiera NaN.
"""
data.City.value_counts()
"""
11. Wyświetl data.info()
"""
data.info()
"""
12. Wyświetl tylko kolumny Borough i Agency i tylko 5 ostatnich linii.
"""
"""
13. Wyświetl tylko te dane, dla których wartość z kolumny Agency jest równa
NYPD. Zlicz ile jest takich przykładów.
@ -68,7 +69,6 @@ NYPD. Zlicz ile jest takich przykładów.
14. Wyświetl wartość minimalną i maksymalną z kolumny Longitude.
"""
"""
15. Dodaj kolumne diff, która powstanie przez sumowanie kolumn Longitude i Latitude.
"""