Last active
December 25, 2015 09:19
-
-
Save cherihung/6953242 to your computer and use it in GitHub Desktop.
functionize.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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