Solved course1
This commit is contained in:
parent
adfee58250
commit
24f3ab5175
@ -15,7 +15,40 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": 19,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"2\n",
|
||||
"Hello Lumenn\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ename": "AttributeError",
|
||||
"evalue": "module 'math' has no attribute 'average'",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
|
||||
"Cell \u001b[1;32mIn[19], line 6\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[38;5;28mprint\u001b[39m(a)\n\u001b[0;32m 5\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mHello Lumenn\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m----> 6\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43mmath\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43maverage\u001b[49m(\u001b[38;5;28mrange\u001b[39m(\u001b[38;5;241m1\u001b[39m,\u001b[38;5;241m10\u001b[39m)))\n",
|
||||
"\u001b[1;31mAttributeError\u001b[0m: module 'math' has no attribute 'average'"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import math\n",
|
||||
"\n",
|
||||
"a = 2\n",
|
||||
"print(a)\n",
|
||||
"print('Hello Lumenn')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {
|
||||
"slideshow": {
|
||||
"slide_type": "slide"
|
||||
@ -58,22 +91,34 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": 40,
|
||||
"metadata": {
|
||||
"slideshow": {
|
||||
"slide_type": "slide"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"AlicjaBartosz 123\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"user1 = \"Alicja\"\n",
|
||||
"user2 = \"Bartosz\"\n",
|
||||
"user3 = \"Cecylia\""
|
||||
"import typing\n",
|
||||
"\n",
|
||||
"user1: str = \"Alicja\"\n",
|
||||
"user2: str = \"Bartosz\"\n",
|
||||
"user3: int = 123\n",
|
||||
"\n",
|
||||
"print(user1 + user2, user3)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": 24,
|
||||
"metadata": {
|
||||
"slideshow": {
|
||||
"slide_type": "slide"
|
||||
@ -114,7 +159,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 26,
|
||||
"metadata": {
|
||||
"slideshow": {
|
||||
"slide_type": "slide"
|
||||
@ -135,7 +180,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": 36,
|
||||
"metadata": {
|
||||
"slideshow": {
|
||||
"slide_type": "slide"
|
||||
@ -672,6 +717,9 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"collapsed": true,
|
||||
"jupyter": {
|
||||
"outputs_hidden": true
|
||||
},
|
||||
"slideshow": {
|
||||
"slide_type": "slide"
|
||||
}
|
||||
@ -2897,7 +2945,7 @@
|
||||
"metadata": {
|
||||
"celltoolbar": "Slideshow",
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
@ -2911,9 +2959,9 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.3"
|
||||
"version": "3.10.11"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 1
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
|
@ -5,3 +5,8 @@
|
||||
* oblicz pole koła i przypisz wynik do zmniennej `pole`. P = pi * r ** 2
|
||||
* wyświetl wynik na ekran.
|
||||
"""
|
||||
|
||||
pi = 3.14
|
||||
promien = 12
|
||||
|
||||
print(pi * promien ** 2)
|
@ -9,3 +9,6 @@ a = "12"
|
||||
b = "35.5"
|
||||
c = True
|
||||
|
||||
wynik = int(a) + float(b) + int(c)
|
||||
|
||||
print(wynik)
|
||||
|
@ -5,8 +5,8 @@
|
||||
* Wyświetl sumaryczną długość zmiennych firstname i surname.
|
||||
"""
|
||||
|
||||
firstname = "Tomasz"
|
||||
surname = "Dwojak"
|
||||
firstname = "Lumenn"
|
||||
surname = "Silme"
|
||||
|
||||
print(f"Nazywam się {firstname} {surname}.")
|
||||
|
||||
@ -14,4 +14,6 @@ print(firstname.lower())
|
||||
|
||||
print("Nazywam się %s %s" % (firstname, surname))
|
||||
|
||||
fullname = f'{firstname} {surname}'
|
||||
print(fullname, len(fullname))
|
||||
|
||||
|
@ -12,3 +12,15 @@ Poniżej znajduje się lista `websites`.
|
||||
websites = ['google.com', 'facebook.com', 'twitter.com', 'pinterest.com', 'python.org']
|
||||
|
||||
polish_websites = ['onet.pl', 'interia.pl', 'wp.pl']
|
||||
|
||||
|
||||
print(websites.index('pinterest.com'))
|
||||
websites[4] = 'yahoo.com'
|
||||
print(websites)
|
||||
websites.append('bing.com')
|
||||
|
||||
social_networks = websites[1:3]
|
||||
print(social_networks)
|
||||
|
||||
websites.extend(polish_websites)
|
||||
print(websites, len(websites))
|
@ -8,3 +8,8 @@ Korzystając z listy numbers:
|
||||
|
||||
|
||||
numbers = [1, 8, 6, 6, 6, 7, 2, 0, 3, 0, 2, 3, 7, 0, 7, 2, 0, 3, 9, 4]
|
||||
|
||||
print(numbers[1])
|
||||
print(numbers.count(7))
|
||||
print(len(numbers))
|
||||
print(max(numbers))
|
||||
|
@ -14,3 +14,15 @@ iris_setosa = [
|
||||
[4.9, 3, 1.4, 0.2],
|
||||
[4.7, 3.2, 1.3, 0.2],
|
||||
]
|
||||
|
||||
sum = 0
|
||||
for set in iris_setosa:
|
||||
sum += set[1]
|
||||
|
||||
print(sum/len(iris_setosa))
|
||||
|
||||
iris_setosa.append(
|
||||
[5.4, 3.9, 1.7, 0.4]
|
||||
)
|
||||
|
||||
print(iris_setosa)
|
@ -21,5 +21,17 @@ data = {
|
||||
|
||||
cecylia_data = {
|
||||
'name': 'Cecylia',
|
||||
'surname': 'Szymanowska'.
|
||||
'surname': 'Szymanowska'
|
||||
}
|
||||
|
||||
|
||||
print(data['place of birth'])
|
||||
print(data['year of death'] - data['year of birth'])
|
||||
data['place of death'] = 'Istanbul'
|
||||
print(data)
|
||||
data['place of birth'] = 'Zaosie'
|
||||
print(data)
|
||||
data['spouse'] = cecylia_data
|
||||
print(data)
|
||||
print(len(data['occupation']))
|
||||
print(data['spouse']['name'])
|
@ -4,3 +4,10 @@ W zależności czy znajduje się czy też nie, wyświetl na ekranie odpowiedni k
|
||||
"""
|
||||
|
||||
passwords = ['aaAaa', 'aAAAaa', 'aaaaaaA', 'aaaAAAAA', 'aaAAAaa', 'aAaAaA', 'aAaAaAA']
|
||||
|
||||
|
||||
|
||||
if 'aAaAaA' in passwords:
|
||||
print('Exists')
|
||||
else:
|
||||
print('Not exits')
|
@ -11,4 +11,18 @@ Zmienna `points` zawiera liczbę uzyskanych punktów przez studenta.
|
||||
Napisz instrukcję warunką, która wyświetli ocenę studenta w zależności od liczby punktów.
|
||||
"""
|
||||
|
||||
points = 85
|
||||
points = 40
|
||||
|
||||
if points >= 90:
|
||||
print(5.0)
|
||||
elif points >= 80:
|
||||
print(4.5)
|
||||
elif points >= 70:
|
||||
print(4.0)
|
||||
elif points >= 60:
|
||||
print(3.5)
|
||||
elif points >= 50:
|
||||
print(3.0)
|
||||
else:
|
||||
print(2.0)
|
||||
|
||||
|
@ -2,3 +2,4 @@
|
||||
Oblicz sumę liczb od 1 do 678.
|
||||
"""
|
||||
|
||||
print(sum(range(1,678)))
|
@ -21,3 +21,8 @@ rozklad = {
|
||||
4: [],
|
||||
3: []
|
||||
}
|
||||
|
||||
for k in oceny:
|
||||
rozklad[oceny[k]].append(k)
|
||||
|
||||
print(rozklad)
|
@ -31,3 +31,12 @@ occasionals = {
|
||||
'October': 53596,
|
||||
'November': 10516,
|
||||
}
|
||||
|
||||
allrides = {}
|
||||
|
||||
for month in members:
|
||||
allrides[month] = members[month] + occasionals[month]
|
||||
|
||||
print(allrides)
|
||||
print(sum(members.values()))
|
||||
print(allrides['August'] / sum(allrides.values()) * 100)
|
@ -21,3 +21,10 @@ tree_per_sqkm = {
|
||||
"Taiwan": 69593,
|
||||
"Turkey": 11126,
|
||||
}
|
||||
|
||||
for country in tree_per_sqkm:
|
||||
sqkm = tree_per_sqkm[country]
|
||||
if sqkm > 20_000:
|
||||
print(f'Over 20k: {country}')
|
||||
if sqkm > 10_000 and sqkm < 20_000:
|
||||
print(f'Between 10k and 20k: {country}')
|
@ -8,4 +8,10 @@ równa wartości zmniennej `number_of_o`. Jeśli argument jest mniejszy niż 5,
|
||||
Wyświetl ten napis na ekran.
|
||||
"""
|
||||
|
||||
number_of_o = 6
|
||||
number_of_o = 4
|
||||
|
||||
if number_of_o > 5:
|
||||
o = 'O' * number_of_o
|
||||
print(f'N{o}!' )
|
||||
else:
|
||||
print('It\'s not a big \'No!\'')
|
@ -12,4 +12,13 @@
|
||||
text = "this is a string , which i will use for string testing"
|
||||
vocab = [',', 'this', 'is', 'a', 'which', 'for', 'will', 'i']
|
||||
|
||||
text = text.split(' ')
|
||||
|
||||
oov = []
|
||||
|
||||
for word in text:
|
||||
if word not in vocab and word not in oov:
|
||||
oov.append(word)
|
||||
|
||||
print(oov)
|
||||
|
||||
|
@ -7,3 +7,22 @@ Ciąg Fibonacciego:
|
||||
a[0] = 1, a[1] = 1, a[n] = a[n-1] + a[n-2] dla n>=2
|
||||
|
||||
"""
|
||||
|
||||
def fibonacciValue(limit, currentValue=1, previousValue=1):
|
||||
if currentValue < limit:
|
||||
print(currentValue)
|
||||
fibonacciValue(limit, currentValue + previousValue, currentValue)
|
||||
else:
|
||||
return
|
||||
|
||||
def fibonacciSteps(stepLimit, currentValue = 1, previousValue = 1, step = 0):
|
||||
if step < stepLimit:
|
||||
print(currentValue)
|
||||
step += 1
|
||||
fibonacciSteps(stepLimit, currentValue + previousValue, currentValue, step)
|
||||
else:
|
||||
return
|
||||
|
||||
fibonacciValue(100)
|
||||
|
||||
fibonacciSteps(10)
|
@ -7,7 +7,12 @@ przez 3 lub 5 mniejszych niż 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
|
||||
|
||||
input = 100
|
||||
print(sum_div35(input))
|
||||
# dla n =100 poprawna odpowiedź to 2318
|
||||
|
@ -3,4 +3,20 @@ Otwórz plik `zen_of_python.txt` i zlicz liczbę linii i słów w tym pliku.
|
||||
Następnie przerób kod na funkcję, która jako argument będzie przyjmować ściężkę do pliku i będzie zwracać
|
||||
słownik z dwoma kluczami: `liczba_linii` i `liczba_slow`.
|
||||
"""
|
||||
import pathlib
|
||||
|
||||
|
||||
def read_metadata(path):
|
||||
f = open(path, 'r')
|
||||
file_content = f.read()
|
||||
|
||||
response = {
|
||||
'liczba_linii': file_content.count('\n'),
|
||||
'liczba_slow': len(file_content.split())
|
||||
}
|
||||
|
||||
return response
|
||||
|
||||
|
||||
|
||||
print(read_metadata(f'{pathlib.Path(__file__).parent.resolve()}\..\zen_of_python.txt'))
|
||||
|
@ -7,6 +7,8 @@ Zadania: Zaimportuj bibliotekę statistics, która zawiera funckje do obliczenia
|
||||
Każda z tych funkcji przyjmuje jeden argument: listę wartości.
|
||||
"""
|
||||
|
||||
import statistics
|
||||
|
||||
members = {
|
||||
'April': 211819,
|
||||
'May': 682758,
|
||||
@ -17,3 +19,8 @@ members = {
|
||||
'October': 444177,
|
||||
'November': 136791,
|
||||
}
|
||||
|
||||
print('Mean:', statistics.mean(members.values()))
|
||||
print('Median:', statistics.median(members.values()))
|
||||
print('Variance:', statistics.variance(members.values()))
|
||||
print('Stdev:', statistics.stdev(members.values()))
|
@ -8,3 +8,21 @@ Biblioteka math posiada funkcję hypot, która oblicza odległość punktu od ś
|
||||
* Oblicz stosunek liczby punktów, dla których odległość wynosiła mniej niż 1 do całkowitej liczby punktów. Pomnóż tę wartocść przez 4.
|
||||
* Podstaw za n wartości 100, 1000, 1000000. Do jakiej wartości zbiegają wartości?
|
||||
"""
|
||||
|
||||
import math
|
||||
import random
|
||||
|
||||
cntLessThanOne = 0
|
||||
repetitions = 10000
|
||||
|
||||
for i in range(0,repetitions):
|
||||
x = random.random()
|
||||
y = random.random()
|
||||
distance = math.hypot(x, y)
|
||||
print(x, y, distance)
|
||||
if distance < 1:
|
||||
cntLessThanOne += 1
|
||||
|
||||
|
||||
print(cntLessThanOne)
|
||||
print(cntLessThanOne/repetitions * 4)
|
Loading…
Reference in New Issue
Block a user