Skip to content

Instantly share code, notes, and snippets.

@leahbannon
Forked from cherihung/makesandwich.py
Created October 19, 2013 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leahbannon/7058082 to your computer and use it in GitHub Desktop.
Save leahbannon/7058082 to your computer and use it in GitHub Desktop.
def makeSand(haspb, hasjelly, slicesofbread):
breadneeded = 2.0
if haspb == True: #have peanut butter
numofsand = slicesofbread/breadneeded #calculate number of sandwich I can make from bread
sandtype = "peanut butter" #set default sandwich type
if hasjelly == True: #have jelly too
sandtype = "peanut butter and jelly" #set sandwich type to include jelly
#start counting number of sandwiches I can make
if numofsand > 1: #enough bread for whole sandwiches
num = str(numofsand).replace(".0",""); #removes .0 from whole number float
print "I have enough bread for {0} {1} sandwiches!".format(num,sandtype)
elif numofsand == 1: #enough bread for ony 1 sandwich
print "I only have bread for just 1 {0} sandwich.".format(sandtype)
elif numofsand >0 and numofsand <1: #enough to make some sandwiches
print "I have enough bread for {0} partial {1} sandwich. At least I can eat.".format(numofsand,sandtype)
else: #no sandwich at all
print "Boo! I don't have enough bread to make a {0}.".format(sandtype)
#end counting
else: #have no peanut butter
print "#BIGFAIL I have no peanut butter. Go buy peanut butter."
makeSand(True, True, 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment