forked from IvarsKarpics/git_tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercises.py
More file actions
79 lines (56 loc) · 1.85 KB
/
exercises.py
File metadata and controls
79 lines (56 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import sys
import warnings
import numpy as np
def test_deprecation_warning():
warnings.warn("This is a deprecated function, will disappear", DeprecationWarning)
print 'still, the function continues'
def decypher(s):
"""Knowing that k -> m, o -> q, e -> g this function
decyphers the string s and returns readable text."""
return "".join(map(chr, [97+(ord(c)-95)%26 if c.isalpha() else ord(c) for c in s]))
def test_decypher():
test_string = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddga"\
"gclr ylb rfyr'q ufw rfgq rcvr gq qm jmle."
assert decypher(test_string) == "i hope you didnt translate it by hand. thats what computers are for. doing it in"\
" by hand is inefficient and that's why this text is so long."
def sum_first_integers(N):
"""Function will return sum of integers up to and including N
Args:
N (int): Integer to go up to
Returns:
int: Sum of first N integers
"""
return N*(N-1)/2
def is_pangram(sentence):
"""Detect whether a sentence is a pangram
"""
ref_sentence="thequickbrownfoxjumpsoverthelazydog"
sentence = sentence.lower()
sentence = sentence.replace(" ", "")
return not (set(ref_sentence) - set(sentence))
def is_vowel(c):
"""
This was a difficult
:param c: a letter
:type: string
"""
return c in 'aeoiuy'
def sum_n(number):
"""
Function that returns the sum of the first N integers.
"""
numbers = np.arange(int(number)+1)
return np.sum(numbers)
def sum(numbers):
total = 0;
for num in numbers:
total += num
return total;
>>>>>>> 702082a5f917009d03b6629abc4bfcae1b95d79c
def multiply(numbers):
total = 1;
for num in numbers:
total *= num
return total;
if __name__ == '__main__':
pass