1
0
forked from tdwojak/Python2017

Zadanie domowe 1

This commit is contained in:
s45166 2017-12-01 22:48:15 +01:00
parent d5755b6965
commit a07b7a1613
11 changed files with 76 additions and 12 deletions

View File

@ -7,7 +7,8 @@ która zawiera tylko elementy z list o parzystych indeksach.
"""
def even_elements(lista):
pass
x = lista[::2]
return x
def tests(f):

View File

@ -6,7 +6,13 @@
"""
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):
inputs = [[2015], [2012], [1900], [2400], [1977]]

View File

@ -13,7 +13,12 @@ jak 'set', która przechowuje elementy bez powtórzeń.)
def oov(text, vocab):
pass
finalList = []
wordList = text.split(" ")
for word in wordList:
if word not in vocab:
finalList.append(word)
return finalList

View File

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

View File

@ -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.
"""
import math
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):
inputs = [[(2.3, 4.3, -7.5), (2.3, 8.5, -7.5)]]

View File

@ -10,7 +10,12 @@ ma być zwracany napis "It's not a Big 'No!'".
"""
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):
inputs = [[5], [6], [2]]

View File

@ -6,7 +6,11 @@ Napisz funkcję char_sum, która dla zadanego łańcucha zwraca
sumę kodów ASCII znaków.
"""
def char_sum(text):
pass
letterSum = 0
for letter in text:
letterSum += ord(letter)
return letterSum
def tests(f):
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):
pass
finalSum = 0
for i in range(1,n):
if i % 3 == 0 or i % 5 == 0:
finalSum += i
return finalSum
def tests(f):
inputs = [[10], [100], [3845]]

View File

@ -9,7 +9,20 @@ Np. leet('leet') powinno zwrócić '1337'.
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):

View File

@ -9,11 +9,21 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
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):
inputs = [['pokemon'], ['do not want'], 'POKEMON']
inputs = [ ['pokemon'], ['do not want'], ['POKEMON']]
outputs = ['PoKeMoN', 'Do nOt wAnT', 'POKEMON']
for input, output in zip(inputs, outputs):

View File

@ -9,7 +9,14 @@ Oba napisy będą składać się wyłacznie z małych liter.
"""
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):