Решение на doge от Йончо Йончев

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

Към профила на Йончо Йончев

Резултати

  • 10 точки от тестове
  • 3 отнети точки
  • 7 точки общо
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)

Код

#homework 1, problem 1
def wow_such_much(start,end):
ans=[]
if start>end:
return ans
else:
for x in range (start,end):
if x %15==0:
ans.append('suchmuch')
elif x %5==0:
ans.append('much')
elif x %3==0:
ans.append('such')
else:
ans.append(str(x))
return ans
#homework 1, problem 2
import re
def count_doge_words(str):
spamItems= ['wow','lol', 'so','such','much','very']
wordCount = dict((x,0) for x in spamItems)
itter=0
for spam in re.findall(r"\w+", str):
if spam in wordCount:
wordCount[spam] += 1
itter+=1
return itter

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

...............
----------------------------------------------------------------------
Ran 15 tests in 0.008s

OK

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

Йончо обнови решението на 11.03.2014 12:34 (преди около 10 години)

+'''homework 1, problem 1'''
+def wow_such_much(start,end):
+ list=[]
+ if start>end:
+ return []
+ else:
+ for x in range (start,end):
+ if x %15==0:
+ list.append('suchmuch')
+ elif x %5==0:
+ list.append('much')
+ elif x %3==0:
+ list.append('such')
+ else:
+ list.append(x)
+ return list;
+
+''' problem 1, tests'''
+print(wow_such_much(1, 16))
+
+
+
+''' homework 1, problem 2'''
+def count_doge_words(str):
+ i=0
+ dic= ['wow','lol', 'so','such','much','very']
+ for word in dic:
+ if word in str:
+ i+=1
+ return i
+
+''' problem 2, tests'''
+print(count_doge_words("wow much hard such difficult"))
  • Погледни PEP8, за да видиш къде ти липсват интервали
  • list е много лошо име, тъй като така скриваш конструктор
  • Много от имената ти изобщо не описват какво държиш в променливата
  • Махни print-овете
  • Нямаш нужда от тези коментари
  • В първата функция дори числата трябва да станат стрингове, пусни си примерните тестове!

Йончо обнови решението на 11.03.2014 16:17 (преди около 10 години)

'''homework 1, problem 1'''
def wow_such_much(start,end):
list=[]
if start>end:
return []
else:
for x in range (start,end):
if x %15==0:
list.append('suchmuch')
elif x %5==0:
list.append('much')
elif x %3==0:
list.append('such')
else:
list.append(x)
return list;
''' problem 1, tests'''
print(wow_such_much(1, 16))
''' homework 1, problem 2'''
+'''Not counting new occurance of the word, should be fixed'''
def count_doge_words(str):
i=0
dic= ['wow','lol', 'so','such','much','very']
for word in dic:
if word in str:
i+=1
return i
''' problem 2, tests'''
print(count_doge_words("wow much hard such difficult"))

Йончо обнови решението на 12.03.2014 10:47 (преди около 10 години)

-'''homework 1, problem 1'''
+#homework 1, problem 1
def wow_such_much(start,end):
- list=[]
- if start>end:
- return []
- else:
- for x in range (start,end):
- if x %15==0:
- list.append('suchmuch')
- elif x %5==0:
- list.append('much')
- elif x %3==0:
- list.append('such')
- else:
- list.append(x)
- return list;
+ ans=[]
+ if start>end:
+ return ans
+ else:
+ for x in range (start,end):
+ if x %15==0:
+ ans.append('suchmuch')
+ elif x %5==0:
+ ans.append('much')
+ elif x %3==0:
+ ans.append('such')
+ else:
+ ans.append(str(x))
+ return ans
-''' problem 1, tests'''
-print(wow_such_much(1, 16))
+
-
+#homework 1, problem 2
-
+import re
-
+def count_doge_words(str):
-''' homework 1, problem 2'''
+ spamItems= ['wow','lol', 'so','such','much','very']
-'''Not counting new occurance of the word, should be fixed'''
+ wordCount = dict((x,0) for x in spamItems)
-def count_doge_words(str):
+ itter=0
- i=0
+ for spam in re.findall(r"\w+", str):
- dic= ['wow','lol', 'so','such','much','very']
+ if spam in wordCount:
- for word in dic:
+ wordCount[spam] += 1
- if word in str:
+ itter+=1
- i+=1
+ return itter
- return i
-
-''' problem 2, tests'''
-print(count_doge_words("wow much hard such difficult"))