Fork me on GitHub

Coding Bat 2

by Sierra Moore

16 Feb 2014

Screenshot

codingbat2

3 Interesting Exercises

Logic 2 lucky_sum - simple, logical and fun

def lucky_sum(a, b, c):
 if a == 13:
   return 0
 elif b == 13:
   return a
 elif c == 13:
   return a + b
 else:
   return a + b + c

String 2 count_hi I forgot how to do this one for a moment.

def count_hi(str):
 a = str.split('hi')
 return len(a) - 1

Warmup 2 array123

def array123(nums):
    # Note: iterate with length-2, so can use i+1 and i+2 in the loop
  for i in range(len(nums)-2):
    if nums[i]==1 and nums[i+1]==2 and nums[i+2]==3:
      return True
  return False
Sierra is a first year MSIS student Find Sierra Moore on Twitter, Github, and on the web.
comments powered by Disqus