forked from tdwojak/Python2017
ćwiczenia 1.1
This commit is contained in:
parent
86d33a2a5d
commit
c6a24f1f8e
@ -10,7 +10,11 @@ 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
|
if len(x)!=len(y):
|
||||||
|
return 'Error'
|
||||||
|
else:
|
||||||
|
return ((x[0]-y[0])**2+(x[1]-y[1])**2+(x[2]-y[2])**2)**(1/2)
|
||||||
|
|
||||||
|
|
||||||
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,13 @@ 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:
|
||||||
|
S="N"
|
||||||
|
for i in range(n):
|
||||||
|
S+="O"
|
||||||
|
return S+"!"
|
||||||
|
|
||||||
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(i) for i 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,12 @@ przez 3 lub 5 mniejszych niż n.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def sum_div35(n):
|
def sum_div35(n):
|
||||||
pass
|
sum=0
|
||||||
|
for i in range(n):
|
||||||
|
if (i%5==0) or (i%3==0):
|
||||||
|
sum+=i
|
||||||
|
return sum
|
||||||
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [[10], [100], [3845]]
|
inputs = [[10], [100], [3845]]
|
||||||
|
@ -9,7 +9,15 @@ Np. leet('leet') powinno zwrócić '1337'.
|
|||||||
|
|
||||||
|
|
||||||
def leet_speak(text):
|
def leet_speak(text):
|
||||||
pass
|
tekst=""
|
||||||
|
slownik = {"e": "3", "l": "1", "o": "0", "t":"7"}
|
||||||
|
for i in text:
|
||||||
|
if i in slownik:
|
||||||
|
tekst+=slownik[i]
|
||||||
|
else:
|
||||||
|
tekst+=i
|
||||||
|
return tekst
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
|
@ -9,7 +9,14 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
|
|||||||
|
|
||||||
|
|
||||||
def pokemon_speak(text):
|
def pokemon_speak(text):
|
||||||
pass
|
s=""
|
||||||
|
for i in range(len(text)):
|
||||||
|
if (i%2==0):
|
||||||
|
s+=text[i].upper()
|
||||||
|
else:
|
||||||
|
s+=text[i]
|
||||||
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
|
@ -9,8 +9,11 @@ Oba napisy będą składać się wyłacznie z małych liter.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def common_chars(string1, string2):
|
def common_chars(string1, string2):
|
||||||
pass
|
b =[]
|
||||||
|
for i in sorted(string1):
|
||||||
|
if (i in sorted(string2)) and i!=" " and i not in b:
|
||||||
|
b.append(i)
|
||||||
|
return b
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [["this is a string", "ala ma kota"]]
|
inputs = [["this is a string", "ala ma kota"]]
|
||||||
|
Loading…
Reference in New Issue
Block a user