forked from tdwojak/Python2017
Praca domowa nr 1
Rozwiązanie - Piotr Bystrzycki - nr indeksu 45146
This commit is contained in:
parent
3a65bc85f2
commit
6c2b8ac2f9
@ -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]]
|
||||
|
@ -13,7 +13,11 @@ jak 'set', która przechowuje elementy bez powtórzeń.)
|
||||
|
||||
|
||||
def oov(text, vocab):
|
||||
pass
|
||||
rett = list()
|
||||
for s in text.lower().split():
|
||||
if not s in vocab:
|
||||
rett.append(s)
|
||||
return set(rett)
|
||||
|
||||
|
||||
|
||||
|
@ -7,7 +7,12 @@ 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
|
||||
sum = 0
|
||||
for i in range(n+1):
|
||||
sum += i
|
||||
return sum
|
||||
|
||||
|
||||
def tests(f):
|
||||
|
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import math as mt
|
||||
|
||||
"""
|
||||
Napisz funkcję euclidean_distance obliczającą odległość między
|
||||
@ -10,7 +11,15 @@ np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5.
|
||||
"""
|
||||
|
||||
def euclidean_distance(x, y):
|
||||
pass
|
||||
x1 = x[0]
|
||||
y1 = x[1]
|
||||
z1 = x[2]
|
||||
|
||||
x2 = y[0]
|
||||
y2 = y[1]
|
||||
z2 = y[2]
|
||||
|
||||
return mt.sqrt((x1 - x2)**2 + (y1 - y2)**2 + (z1 - z2)**2)
|
||||
|
||||
def tests(f):
|
||||
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):
|
||||
pass
|
||||
if n < 5:
|
||||
return "It's not a Big 'No!'"
|
||||
t = list('N')
|
||||
for i in range(n):
|
||||
t.append('O')
|
||||
return ''.join(t) + '!'
|
||||
|
||||
|
||||
def tests(f):
|
||||
inputs = [[5], [6], [2]]
|
||||
|
@ -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
|
||||
s = 0
|
||||
for z in text:
|
||||
s +=ord(z)
|
||||
return s
|
||||
|
||||
def tests(f):
|
||||
inputs = [["this is a string"], ["this is another string"]]
|
||||
|
@ -7,7 +7,11 @@ przez 3 lub 5 mniejszych niż n.
|
||||
"""
|
||||
|
||||
def sum_div35(n):
|
||||
pass
|
||||
s = 0
|
||||
for i in range(n):
|
||||
if (i % 3 == 0) or (i % 5 == 0):
|
||||
s+=i
|
||||
return s
|
||||
|
||||
def tests(f):
|
||||
inputs = [[10], [100], [3845]]
|
||||
|
@ -7,9 +7,17 @@ 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'.
|
||||
"""
|
||||
|
||||
import string
|
||||
|
||||
def leet_speak(text):
|
||||
pass
|
||||
dt = {"e":"3", "l":"1", "o":"0", "t":"7"}
|
||||
ltx = text.lower()
|
||||
ret = text + ""
|
||||
for k in list(ltx):
|
||||
v = dt.get(k)
|
||||
if v is not None:
|
||||
ret = ret.replace(k, v)
|
||||
return ret
|
||||
|
||||
|
||||
def tests(f):
|
||||
|
@ -7,13 +7,19 @@ Napisz funkcję pokemon_speak, która zamienia w podanym napisie co drugą liter
|
||||
na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
|
||||
"""
|
||||
|
||||
import string as str
|
||||
|
||||
def pokemon_speak(text):
|
||||
pass
|
||||
lt = list(text)
|
||||
for i in range(len(lt)):
|
||||
if i%2 == 0:
|
||||
lt[i] = lt[i].upper()
|
||||
return ''.join(lt)
|
||||
|
||||
|
||||
|
||||
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):
|
||||
|
@ -9,8 +9,13 @@ Oba napisy będą składać się wyłacznie z małych liter.
|
||||
"""
|
||||
|
||||
def common_chars(string1, string2):
|
||||
pass
|
||||
|
||||
t1 = list(''.join(string1.split(' ')))
|
||||
t2 = list(''.join(string2.split(' ')))
|
||||
rett = list()
|
||||
for lit in t1:
|
||||
if lit in t2:
|
||||
rett.append(lit)
|
||||
return sorted(set(rett))
|
||||
|
||||
def tests(f):
|
||||
inputs = [["this is a string", "ala ma kota"]]
|
||||
|
@ -6,7 +6,7 @@ def suma(a, b):
|
||||
"""
|
||||
Napisz funkcję, która zwraca sumę elementów.
|
||||
"""
|
||||
pass
|
||||
return a+b
|
||||
|
||||
def tests(f):
|
||||
inputs = [(2, 3), (0, 0), (1, 1)]
|
||||
|
Loading…
Reference in New Issue
Block a user