@@ -172,6 +172,12 @@ data = [num for num in data if int(num, 2) % 5 == 0]
172
172
print (' ,' .join(data))
173
173
```
174
174
175
+ ``` python
176
+ ''' Solution by: hajimalung baba
177
+ '''
178
+ print (* (binary for binary in input ().split(' ,' ) if int (binary,base = 2 )% 5 == 0 ))
179
+ ```
180
+
175
181
---
176
182
177
183
# Question 12
@@ -246,6 +252,17 @@ print(",".join(lst))
246
252
print (' ,' .join([str (num) for num in range (1000 , 3001 ) if all (map (lambda num : int (num) % 2 == 0 , str (num)))]))
247
253
```
248
254
255
+ ``` python
256
+ ''' Solution by: hajimalung
257
+ '''
258
+ from functools import reduce
259
+ # using reduce to check if the number has only even digits or not
260
+ def is_even_and (bool_to_compare ,num_as_char ):
261
+ return int (num_as_char)% 2 == 0 and bool_to_compare
262
+
263
+ print (* (i for i in range (1000 ,3001 ) if reduce (is_even_and,str (i),True )),sep = ' ,' )
264
+ ```
265
+
249
266
---
250
267
251
268
# Question 13
@@ -350,6 +367,20 @@ for item in sen:
350
367
digit += 1
351
368
print (f " LETTERS : { alp} \n DIGITS : { digit} " )
352
369
```
370
+ ``` python
371
+ ''' Solution by: hajimalung
372
+ '''
373
+ # using reduce for to count
374
+ from functools import reduce
375
+
376
+ def count_letters_digits (counters ,char_to_check ):
377
+ counters[0 ] += char_to_check.isalpha()
378
+ counters[1 ] += char_to_check.isnumeric()
379
+ return counters
380
+
381
+ print (' LETTERS {0} \n DIGITS {1} ' .format(* reduce (count_letters_digits,input (),[0 ,0 ])))
382
+ ```
383
+
353
384
---
354
385
355
386
## Conclusion
0 commit comments