forked from tdwojak/Python2018
labs02 first part of tasks
This commit is contained in:
parent
41207a9a35
commit
a5f73d423a
@ -7,8 +7,11 @@ która zawiera tylko elementy z list o parzystych indeksach.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def even_elements(lista):
|
def even_elements(lista):
|
||||||
pass
|
result = []
|
||||||
|
for i in range(len(lista)):
|
||||||
|
if i % 2 == 0:
|
||||||
|
result.append(lista[i])
|
||||||
|
return result
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [[[1, 2, 3, 4, 5, 6]], [[]], [[41]]]
|
inputs = [[[1, 2, 3, 4, 5, 6]], [[]], [[41]]]
|
||||||
|
@ -6,7 +6,23 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def days_in_year(days):
|
def days_in_year(days):
|
||||||
pass
|
if days % 4 == 0:
|
||||||
|
if days % 100 == 0:
|
||||||
|
if days % 400 == 0:
|
||||||
|
return 366
|
||||||
|
else:
|
||||||
|
return 365
|
||||||
|
else:
|
||||||
|
return 366
|
||||||
|
else:
|
||||||
|
return 365
|
||||||
|
|
||||||
|
# To determine whether a year is a leap year, follow these steps:
|
||||||
|
# If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5.
|
||||||
|
# If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4.
|
||||||
|
# If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5.
|
||||||
|
# The year is a leap year (it has 366 days).
|
||||||
|
# The year is not a leap year (it has 365
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [[2015], [2012], [1900], [2400], [1977]]
|
inputs = [[2015], [2012], [1900], [2400], [1977]]
|
||||||
|
@ -13,9 +13,8 @@ jak 'set', która przechowuje elementy bez powtórzeń.)
|
|||||||
|
|
||||||
|
|
||||||
def oov(text, vocab):
|
def oov(text, vocab):
|
||||||
pass
|
words = text.lower().split()
|
||||||
|
return (set(words) - set(vocab))
|
||||||
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [("this is a string , which i will use for string testing",
|
inputs = [("this is a string , which i will use for string testing",
|
||||||
|
@ -7,7 +7,10 @@ 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):
|
||||||
pass
|
if n < 1:
|
||||||
|
return 0
|
||||||
|
else:
|
||||||
|
return sum(i for i in range(1, n+1))
|
||||||
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import math as m
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Napisz funkcję euclidean_distance obliczającą odległość między
|
Napisz funkcję euclidean_distance obliczającą odległość między
|
||||||
@ -10,7 +10,10 @@ 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
|
dist = 0
|
||||||
|
for i, j in zip(x, y):
|
||||||
|
dist += (i-j) ** 2
|
||||||
|
return m.sqrt(dist)
|
||||||
|
|
||||||
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)]]
|
||||||
|
@ -10,7 +10,10 @@ ma być zwracany napis "It's not a Big 'No!'".
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def big_no(n):
|
def big_no(n):
|
||||||
pass
|
if n < 5:
|
||||||
|
return "It's not a Big \'No!\'"
|
||||||
|
else:
|
||||||
|
return "N" + n * "O" + "!"
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [[5], [6], [2]]
|
inputs = [[5], [6], [2]]
|
||||||
|
@ -6,7 +6,7 @@ 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
|
return sum(ord(x) for x in text)
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [["this is a string"], ["this is another string"]]
|
inputs = [["this is a string"], ["this is another string"]]
|
||||||
|
@ -7,7 +7,7 @@ przez 3 lub 5 mniejszych niż n.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def sum_div35(n):
|
def sum_div35(n):
|
||||||
pass
|
return sum(x for x in range(n) if (x % 3 == 0 or x % 5 == 0))
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [[10], [100], [3845]]
|
inputs = [[10], [100], [3845]]
|
||||||
|
@ -9,7 +9,7 @@ Oba napisy będą składać się wyłacznie z małych liter.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def common_chars(string1, string2):
|
def common_chars(string1, string2):
|
||||||
pass
|
return sorted(set(string1.replace(' ', '')) & set(string2.replace(' ', '')))
|
||||||
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
|
Loading…
Reference in New Issue
Block a user