forked from tdwojak/Python2017
Zadanie domowe 1
This commit is contained in:
parent
d5755b6965
commit
a07b7a1613
@ -7,7 +7,8 @@ która zawiera tylko elementy z list o parzystych indeksach.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def even_elements(lista):
|
def even_elements(lista):
|
||||||
pass
|
x = lista[::2]
|
||||||
|
return x
|
||||||
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
|
@ -6,7 +6,13 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def days_in_year(days):
|
def days_in_year(days):
|
||||||
pass
|
if days % 4 == 0 and days % 100 != 0:
|
||||||
|
return 366
|
||||||
|
elif 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]]
|
||||||
|
@ -13,7 +13,12 @@ jak 'set', która przechowuje elementy bez powtórzeń.)
|
|||||||
|
|
||||||
|
|
||||||
def oov(text, vocab):
|
def oov(text, vocab):
|
||||||
pass
|
finalList = []
|
||||||
|
wordList = text.split(" ")
|
||||||
|
for word in wordList:
|
||||||
|
if word not in vocab:
|
||||||
|
finalList.append(word)
|
||||||
|
return finalList
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -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(range(1,n+1))
|
||||||
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
|
@ -9,8 +9,14 @@ trzyelementowe listy liczb zmiennoprzecinkowych.
|
|||||||
np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5.
|
np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import math
|
||||||
def euclidean_distance(x, y):
|
def euclidean_distance(x, y):
|
||||||
pass
|
x1 = x[0]
|
||||||
|
x2 = y[0]
|
||||||
|
y1 = x[1]
|
||||||
|
y2 = y[1]
|
||||||
|
z = math.sqrt((x1-x2)**2+(y1-y2)**2)
|
||||||
|
return z
|
||||||
|
|
||||||
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,12 @@ 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:
|
||||||
|
bigO = "O"*n
|
||||||
|
return "N"+bigO+"!"
|
||||||
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [[5], [6], [2]]
|
inputs = [[5], [6], [2]]
|
||||||
|
@ -6,7 +6,11 @@ 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
|
letterSum = 0
|
||||||
|
for letter in text:
|
||||||
|
letterSum += ord(letter)
|
||||||
|
return letterSum
|
||||||
|
|
||||||
|
|
||||||
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,11 @@ przez 3 lub 5 mniejszych niż n.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def sum_div35(n):
|
def sum_div35(n):
|
||||||
pass
|
finalSum = 0
|
||||||
|
for i in range(1,n):
|
||||||
|
if i % 3 == 0 or i % 5 == 0:
|
||||||
|
finalSum += i
|
||||||
|
return finalSum
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [[10], [100], [3845]]
|
inputs = [[10], [100], [3845]]
|
||||||
|
@ -9,7 +9,20 @@ Np. leet('leet') powinno zwrócić '1337'.
|
|||||||
|
|
||||||
|
|
||||||
def leet_speak(text):
|
def leet_speak(text):
|
||||||
pass
|
letterList = list(text)
|
||||||
|
x = 0
|
||||||
|
for i in letterList:
|
||||||
|
if i == 'e':
|
||||||
|
letterList[x] = '3'
|
||||||
|
elif i == 'l':
|
||||||
|
letterList[x] = '1'
|
||||||
|
elif i == 'o':
|
||||||
|
letterList[x] = '0'
|
||||||
|
elif i == 't':
|
||||||
|
letterList[x] = '7'
|
||||||
|
x += 1
|
||||||
|
finalOutput = ''.join(letterList)
|
||||||
|
return finalOutput
|
||||||
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
|
@ -9,11 +9,21 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
|
|||||||
|
|
||||||
|
|
||||||
def pokemon_speak(text):
|
def pokemon_speak(text):
|
||||||
pass
|
letterList = list(text)
|
||||||
|
|
||||||
|
x = 0
|
||||||
|
for i in letterList:
|
||||||
|
if i.isalpha() and (x == 0 or x % 2 == 0):
|
||||||
|
letterList[x] = i.upper()
|
||||||
|
x += 1
|
||||||
|
finalOutput = ''.join(letterList)
|
||||||
|
return finalOutput
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [['pokemon'], ['do not want'], 'POKEMON']
|
inputs = [ ['pokemon'], ['do not want'], ['POKEMON']]
|
||||||
outputs = ['PoKeMoN', 'Do nOt wAnT', 'POKEMON']
|
outputs = ['PoKeMoN', 'Do nOt wAnT', 'POKEMON']
|
||||||
|
|
||||||
for input, output in zip(inputs, outputs):
|
for input, output in zip(inputs, outputs):
|
||||||
|
@ -9,7 +9,14 @@ Oba napisy będą składać się wyłacznie z małych liter.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def common_chars(string1, string2):
|
def common_chars(string1, string2):
|
||||||
pass
|
finalList = []
|
||||||
|
for i in string1:
|
||||||
|
if i.isalpha() and i in string2 and i not in finalList:
|
||||||
|
finalList.append(i)
|
||||||
|
for j in string2:
|
||||||
|
if j.isalpha() and j in string1 and j not in finalList:
|
||||||
|
finalList.append(j)
|
||||||
|
return sorted(finalList)
|
||||||
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
|
Loading…
Reference in New Issue
Block a user