Codingbat - sum67 (Python)

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

I would like to thank you from the bottom of my heart for the every single video. I learned a lot from you. You are an amazing teacher. Your students are really lucky to have you!

eminedogan
Автор

I just finished the python series; it was terrific, and I learned a lot. This was the problem that caused me the greatest grief. I ended up going with the following, less-elegant, code. Thank you. I really enjoyed the practice!


NUMS_TOTAL = sum(nums)
sums_6to7 = 0
dx7 = 0

for x in range(nums.count(6)):
try:
dx6 = nums.index(6, dx7)
dx7 = nums.index(7, dx6)
sums_6to7 = sums_6to7 + sum(nums[dx6: dx7 + 1])
except ValueError:
break

return NUMS_TOTAL - sums_6to7

hatpeach
Автор

i was wondering how to do it ina properway.
heres mine code :x
def sum67(n):
c = 0
if 6 in n:
L = n[:n.index(6)]
L2 = n[n.index(7)+1:]
n = L + L2
for i in range(len(n)):
c += n[i]
else:
for i in range(len(n)):
c += n[i]
return c

apkog
welcome to shbcf.ru