1
0
forked from tdwojak/Python2017

wszystkie zadania

This commit is contained in:
s45452 2017-11-24 22:25:50 +01:00
parent d5755b6965
commit 71b8bf415c
11 changed files with 104 additions and 16 deletions

View File

@ -5,9 +5,17 @@
Zad 2. Napisz funkcję even_elements zwracającą listę,
która zawiera tylko elementy z list o parzystych indeksach.
"""
def even_elements(b):
lista=(b[::2])
"""listaa=[]
for i in range(3):
for k in range (1):
#print(inputs[i][0][::2])
listaa.append(lista[i][0][::2])"""
#lista(str(lista).strip('[]'))
return lista
def even_elements(lista):
pass
def tests(f):

View File

@ -6,7 +6,11 @@
"""
def days_in_year(days):
pass
if days % 4 == 0 and days % 100 > 0 or 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
test = list(text.split(' '))
lista = list(set(test) - set(vocab))
lista.reverse()
return lista

View File

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

View File

@ -8,9 +8,17 @@ dwoma punktami przestrzeni trójwymiarowej. Punkty są dane jako
trzyelementowe listy liczb zmiennoprzecinkowych.
np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5.
"""
from math import *
def euclidean_distance(x, y):
pass
a = int(x[0])
b = x[1]
c = x[2]
d = int(y[0])
e = y[1]
f = y[2]
wartosc =((d-a)**2)+((e-b)**2)+((f-c)**2)
return fabs(sqrt(wartosc))
def tests(f):
inputs = [[(2.3, 4.3, -7.5), (2.3, 8.5, -7.5)]]

View File

@ -10,7 +10,17 @@ ma być zwracany napis "It's not a Big 'No!'".
"""
def big_no(n):
pass
list = ["N"]
if n <5:
return "It's not a Big 'No!'"
else:
for i in range(n):
list.append("O")
list.append("!")
return ''.join(list)
def tests(f):
inputs = [[5], [6], [2]]

View File

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

View File

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

View File

@ -7,9 +7,22 @@ na podobnie wyglądające cyfry: 'e' na '3', 'l' na '1', 'o' na '0', 't' na '7'.
Np. leet('leet') powinno zwrócić '1337'.
"""
slownik = {"e": '3', "l": '1', "o": '0', "t": '7'}
def leet_speak(text):
pass
listaa=[]
for i in text:
if i in slownik:
listaa.append(slownik[i])
else:
listaa.append(i)
return ''.join(listaa)
def tests(f):

View File

@ -8,12 +8,21 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
"""
def pokemon_speak(text):
pass
listaa=[]
for i in range(len(text)):
if i%2==0:
listaa.append(text[i].upper())
else:
listaa.append(text[i])
return ''.join(listaa)
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

@ -7,9 +7,22 @@ Napisz funkcję common_chars(string1, string2), która zwraca alfabetycznie
uporządkowaną listę wspólnych liter z lańcuchów string1 i string2.
Oba napisy będą składać się wyłacznie z małych liter.
"""
listaa = []
def common_chars(string1, string2):
pass
for i in string1:
if i != " ":
for j in string2:
if i == j:
listaa.append(i)
else:
pass
return sorted(list(set(listaa)))
def tests(f):