Fork me on GitHub

Codingbat Exercises

by Katie Meyer

05 Feb 2014

Exercises

Logic 1: Cigar Party

def cigar_party(cigars, is_weekend):
  if is_weekend == True:
    if cigars >= 40: #Unlimited cigars on the weekend!
      return True
    else:
      return False
  else:
    if cigars >= 40 and cigars <= 60: #Take it easy, it's a school night
      return True
    else: 
      return False

Input/output

Cigar party

Logic 1: Date fashion

def date_fashion(you, date):
  if (you >= 8 or date >= 8) and you >2 and date >2: #At least one of you is stylish!
    return 2
  elif you <= 2 or date <= 2: #Your date let you down...
    return 0
  else:
    return 1

Input/output

Date

Logic 1: Squirrel play

def squirrel_play(temp, is_summer):
  if is_summer and temp >= 60 and temp <=100: #Squirrels can withstand higher temps in summer?
    return True
  elif is_summer == False and temp >=60 and temp <=90:
    return True
  else:
    return False

Input/output

Play

Checkmarks

Warm up Lists Strings Logic

Katie is a first year MSIS student from Raleigh NC. She's also a Web UI Developer at IBM. Find Katie Meyer on Twitter, Github, and on the web.
comments powered by Disqus