-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarathone
More file actions
359 lines (241 loc) · 6.65 KB
/
Copy pathmarathone
File metadata and controls
359 lines (241 loc) · 6.65 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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# DAY 0 Hello, World
# Read a full line of input from stdin and save it to our dynamically typed variable, input_string.
input_string = input()
# Print a string literal saying "Hello, World." to stdout.
print('Hello, World.')
# TODO: Write a line of code here that prints the contents of input_string to stdout.
print(input_string)
# DAY 1 Data Types
i = 4
d = 4.0
s = 'HackerRank '
# Declare second integer, double, and String variables.
i_2 = input()
d_2 = input()
s_2 = input()
# Read and save an integer, double, and String to your variables.
i_2 = int(i_2)
d_2 = float(d_2)
s_2 = str(s_2)
# Print the sum of both integer variables on a new line.
print(i+i_2)
# Print the sum of the double variables on a new line.
print(d+d_2)
# Concatenate and print the String variables on a new line
# The 's' variable above should be printed first.
print(s+s_2)
# DAY 2 Operators
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'solve' function below.
#
# The function accepts following parameters:
# 1. DOUBLE meal_cost
# 2. INTEGER tip_percent
# 3. INTEGER tax_percent
#
def solve(meal_cost, tip_percent, tax_percent):
# Write your code here
tip_percent = tip_percent*meal_cost/100
tax_percent = tax_percent*meal_cost/100
return print(round(meal_cost+tip_percent+tax_percent))
if __name__ == '__main__':
meal_cost = float(input().strip())
tip_percent = int(input().strip())
tax_percent = int(input().strip())
solve(meal_cost, tip_percent, tax_percent)
# DAY 3 Intro to Conditional Statements
#!/bin/python3
import math
import os
import random
import re
import sys
if __name__ == '__main__':
N = int(input().strip())
if N % 2 != 0:
print('Weird')
elif N % 2 == 0 and N>=2 and N<=5:
print('Not Weird')
elif N % 2 == 0 and N>=6 and N<=20:
print('Weird')
elif N % 2 == 0 and N>20:
print('Not Weird')
# DAY 4: Class vs. Instance
class Person:
def __init__(self,initialAge):
# Add some more code to run some checks on initialAge
self.age = initialAge
if self.age <-5 and self.age>30:
quit()
if self.age<0:
print('Age is not valid, setting age to 0.')
self.age = 0
def amIOld(self):
# Do some computations in here and print out the correct statement to the console
if self.age<13:
print('You are young.')
elif self.age>=13 and self.age<18:
print('You are a teenager.')
else:
print('You are old.')
def yearPasses(self):
# Increment the age of the person in here
self.age +=1
t = int(input())
for i in range(0, t):
age = int(input())
p = Person(age)
p.amIOld()
for j in range(0, 3):
p.yearPasses()
p.amIOld()
print("")
# DAY 5: Loops
#!/bin/python3
import math
import os
import random
import re
import sys
if __name__ == '__main__':
n = int(input().strip())
if n<2 and n>20:
quit()
else:
for i in range(1,11):
a=n*i
print(f'{n} x {i} = {a}')
# DAY 6: Let's Review
# Enter your code here. Read input from STDIN. Print output to STDOUT
# Enter your code here. Read input from STDIN. Print output to STDOUT
how_many_rows = input()
try:
rows_T = int(how_many_rows)
if rows_T<1 or rows_T>10:
quit()
except:
print('Error')
quit()
while rows_T > 0:
STDIN = input()
a = str(STDIN)
a.strip()
if len(a)<2 or len(a)>10_000:
quit()
else:
b = str()
c = str()
for i in range(len(a)):
if i%2 == 0:
b = b + a[i]
else:
c = c + a[i]
STDOUT = b + ' ' + c
print(STDOUT)
rows_T -= 1
#DAY 7: Arrays
#!/bin/python3
import math
import os
import random
import re
import sys
if __name__ == '__main__':
n = int(input().strip())
if n<1 or n>1_000:
quit()
else:
array = []
input_string = input()
list_of_elements = [int(value) for value in input_string.split()]
for el in list_of_elements:
if el>0 and el<10_001:
array.append(el)
if len(array) == n:
array.reverse()
my_output = ''
for i in array:
my_output = my_output + str(i) + ' '
print(my_output.rstrip())
break
else:
continue
else:
print('Error')
# DAY 8: Dictionaries and Maps
# Enter your code here. Read input from STDIN. Print output to STDOUT
n = input()
n = int(n)
if n<1 or n>10 ** 5:
quit()
phoneBook = {}
while len(phoneBook) != n:
one_of_the_phones = input()
one_of_the_phones = one_of_the_phones.split()
if len(one_of_the_phones[1]) == 8:
one_of_the_phones[1] = int(one_of_the_phones[1])
phoneBook[one_of_the_phones[0]] = one_of_the_phones[1]
else:
continue
# try to find name in phoneBook:
import sys
active = True
while active:
name = sys.stdin.readline().strip()
name = name.lower()
if not name:
active = False
elif name in phoneBook:
print(f"{name}={phoneBook.get(name)}")
else:
print('Not found')
# DAY 9: Recursion 3
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'factorial' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER n as parameter.
#
def factorial(n):
# Write your code here
if n <= 1:
return 1
return n * factorial(n-1)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input().strip())
result = factorial(n)
fptr.write(str(result) + '\n')
fptr.close()
# DAY 10: Binary Numbers
#!/bin/python3
import math
import os
import random
import re
import sys
current_number_of_consecutive_1s = 0
maximum_number_of_consecutive_1s = 0
if __name__ == '__main__':
n = int(input().strip())
while n > 1:
if n % 2 == 1:
current_number_of_consecutive_1s += 1
if current_number_of_consecutive_1s > maximum_number_of_consecutive_1s:
maximum_number_of_consecutive_1s = current_number_of_consecutive_1s
elif n % 2 == 0:
current_number_of_consecutive_1s += 0
n = n // 2
print(maximum_number_of_consecutive_1s)