Решение на doge от Мила Боюклиева

Обратно към всички решения

Към профила на Мила Боюклиева

Резултати

  • 8 точки от тестове
  • 1 отнета точка
  • 7 точки общо
  • 12 успешни тест(а)
  • 3 неуспешни тест(а)

Код

def wow_such_much(start, end):
data = []
for i in range(start,end):
if i%3==0 and not i%5==0:
data.append("such")
if i%5==0 and not i%3==0:
data.append("much")
if i%5==0 and i%3==0:
data.append("suchmuch")
elif i%5!=0 and i%3!=0:
data.append(i)
return data
def count_doge_words(sentence):
words = sentence.split()
bad_words = ["wow", "so", "lol", "such", "much", "very"]
counter = 0
for word in words:
if word in bad_words:
counter += 1
return counter
print (wow_such_much(8,16))
print (count_doge_words("Wow wow how so fine"))

Лог от изпълнението

[8, 'such', 'much', 11, 'such', 13, 14, 'suchmuch']
2
............FFF
======================================================================
FAIL: test_suchmuch_to_100 (test.TestSuchMuchDoge)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20141216-14586-19v1wfv/test.py", line 38, in test_suchmuch_to_100
    '92', 'such', '94', 'much', 'such', '97', '98', 'such'])
AssertionError: Lists differ: [1, 2, 'such', 4, 'much', 'suc... != ['1', '2', 'such', '4', 'much'...

First differing element 0:
1
1

Diff is 1840 characters long. Set self.maxDiff to None to see it.

======================================================================
FAIL: test_suchmuch_to_16 (test.TestSuchMuchDoge)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20141216-14586-19v1wfv/test.py", line 20, in test_suchmuch_to_16
    '11', 'such', '13', '14', 'suchmuch'])
AssertionError: Lists differ: [1, 2, 'such', 4, 'much', 'suc... != ['1', '2', 'such', '4', 'much'...

First differing element 0:
1
1

- [1,
+ ['1',
?  + +

-  2,
+  '2',
?  + +

   'such',
-  4,
+  '4',
?  + +

   'much',
   'such',
-  7,
+  '7',
?  + +

-  8,
+  '8',
?  + +

   'such',
   'much',
-  11,
+  '11',
?  +  +

   'such',
-  13,
+  '13',
?  +  +

-  14,
+  '14',
?  +  +

   'suchmuch']

======================================================================
FAIL: test_suchmuch_to_2 (test.TestSuchMuchDoge)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20141216-14586-19v1wfv/test.py", line 14, in test_suchmuch_to_2
    self.assertEqual(solution.wow_such_much(1, 2), ['1'])
AssertionError: Lists differ: [1] != ['1']

First differing element 0:
1
1

- [1]
+ ['1']
?  + +


----------------------------------------------------------------------
Ran 15 tests in 0.045s

FAILED (failures=3)

История (1 версия и 1 коментар)

Мила обнови решението на 12.03.2014 01:54 (преди над 10 години)

+
+def wow_such_much(start, end):
+ data = []
+ for i in range(start,end):
+ if i%3==0 and not i%5==0:
+ data.append("such")
+ if i%5==0 and not i%3==0:
+ data.append("much")
+ if i%5==0 and i%3==0:
+ data.append("suchmuch")
+ elif i%5!=0 and i%3!=0:
+ data.append(i)
+ return data
+
+def count_doge_words(sentence):
+ words = sentence.split()
+ bad_words = ["wow", "so", "lol", "such", "much", "very"]
+ counter = 0
+
+ for word in words:
+ if word in bad_words:
+ counter += 1
+ return counter
+
+print (wow_such_much(8,16))
+print (count_doge_words("Wow wow how so fine"))
  • Махни print-овете
  • Оставяй интервали около операторите
  • Пусни си примерните тестове и ще видиш, че искаме и числата в първата функция да са стрингове
  • Ако използваш elif по-ефективно, проверките ти ще станат по-четими и по-кратки