-
Notifications
You must be signed in to change notification settings - Fork 0
/
previousChallenges.py
executable file
·193 lines (164 loc) · 4.03 KB
/
previousChallenges.py
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#out = []
# for i in range(len(string)):
# if i%2==0:
# out.append(string[i].lower())
# else:
# out.append(string[i].upper())
# return ''.join(out)
def myfunc(string):
output = str()
for i in range(len(string)):
if i%2==0:
output += string[i].lower()
else:
output += string[i].upper()
return output
print(myfunc("hello"))
#%%
def lesser_of_two_evens(a,b):
if(a%2==0 and b%2==0):
if a<b:
return a
else:
return b
else:
if a<b:
return b
else:
return a
print(lesser_of_two_evens(2, 5))
#%%
def animal_crackers(text):
words = text.split()
if len(words)==2:
if words[0][0] == words[1][0]:
return True
return False
animal_crackers("lol mano")
#%%
def makes_twenty(n1,n2):
return (n1+n2==20 or n1==20 or n2==20)
makes_twenty(10,10)
#%%
def old_macdonald(name):
output = name[:3].capitalize()
toJoin = name[3:].capitalize()
return output + toJoin
old_macdonald("macdonald")
#%%
def master_yoda(text):
output = text.split()
output.reverse()
return " ".join(output)
master_yoda("I am home")
# %%
def almost_there(n):
return (n>=90 and n <=110) or (n>=190 and n<=210)
almost_there(150)
# %%
def has_33(nums):
for i in range(len(nums)-1):
if nums[i] == 3 and nums[i+1]==3:
return True
return False
has_33([1,3,3])
# %%
def paper_doll(text):
tab = [letter * 3 for letter in text]
return "".join(tab)
paper_doll("Hello")
# %%
def blackjack(a,b,c):
s = a+b+c
if s>21 and (a==11 or b ==11 or c==11):
s=s-10
if s<=21:
return s
else:
return 'BUST'
blackjack(9,9,11)
# %%
def summer_69(arr):
sum = 0
ignore = False
for num in arr:
if ignore:
if num == 9:
ignore = False
continue
if num == 6:
ignore = True
continue
sum += num
return sum
summer_69([2, 1, 6, 9, 11])
# %%
def spy_game(nums):
zerosAndSevens = str()
for num in nums:
if num == 0 or num == 7:
zerosAndSevens += str(num)
return "007" in zerosAndSevens
spy_game([1,7,2,0,4,5,0])
# %%
from math import sqrt
def count_primes(n):
nums = [num for num in range(2,n+1)]
root = int(sqrt(n)) + 1
counter = 3
for i in range(2, root):
multiplied = i * 2
while multiplied<=n:
if multiplied in nums:
nums.remove(multiplied)
multiplied = i * counter
counter+=1
counter = 3
print(nums)
return len(nums)
count_primes(100)
# %%
from math import pi
def vol(rad):
return (4/3)*pi*rad**3
vol(2)
# %%
def ran_bool(num,low,high):
return num >= low and num <=high
ran_bool(3,1,10)
# %%
def up_low(s):
d = {"upperCase": 0, "lowerCase": 0}
for letter in s:
if letter.isupper():
d["upperCase"] += 1
elif letter.islower():
d["lowerCase"] += 1
print(f"Original string: {s}")
print(f"Upper case letters: {d['upperCase']}")
print(f"Lowercase letters: {d['lowerCase']}")
up_low('Hello Mr. Rogers, how are you this fine Tuesday?')
# %%
def unique_list(lst):
return list(set(lst))
unique_list([1,1,1,1,2,2,3,3,3,3,4,5])
# %%
def multiply(numbers):
out = 1
for number in numbers:
out *= number
return out
multiply([1,2,3,-4])
# %%
def palindrome(s):
return s.replace(' ', '') == s[::-1]
palindrome('helleh')
# %%
import string
def ispangram(str1, alphabet=string.ascii_lowercase):
return set(str1.replace(" ", "").lower()) == set(alphabet)
ispangram("The quick brown fox jumps over the lazy dog")
# %%
def test(a): return a**3
list(map(lambda num: num**3, [1, 2, 3, 4]))
# %%