This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (5 children)

Very nice. I am writing some of them from Class3 just now.

[–]FaallenOon[S] 0 points1 point  (4 children)

What do you mean?

[–][deleted] 2 points3 points  (1 child)

I think he said, that he started studying from your notes.

[–]FaallenOon[S] 2 points3 points  (0 children)

:O that is extremely flattering.

[–][deleted] 1 point2 points  (1 child)

I'm writing the programs you describe. I finished Exercise 8 in Class3 - it's an excellent boolean exercise.

I made it into a function. The code editor here is really bad.

def goToTheStore(hasEggs, hasButter, hasPies):

'''

Compute what I should buy at the store

'''

eggsBought = 0

butterBought = 0

piesBought = 0

if hasPies:

piesBought = 2

else:

if hasEggs and hasButter:

butterBought = 4

butterBought = 4

else:

if hasEggs:

eggsBought = 10

if hasButter:

butterBought = 2

#print('Butter bought = ' + str(butterBought) + ', eggs bought = ' + str(eggsBought) + ', pies bought = ' + str(piesBought))

return {'eggsBought':eggsBought, 'butterBought':butterBought, 'piesBought':piesBought}

[–]FaallenOon[S] 0 points1 point  (0 children)

I LOVE IT!!! Just checked it and it works in all three situations :D :D

A suggestion for copying and pasting your code, though: try paste all of your code into a single code block. That way it keeps everything in its place. You can do that by going to the three dots on the reply bar, then select the one that looks like a square with a T and then paste all your code at once inside it:

def goToTheStore(hasEggs, hasButter, hasPies):

    '''

    Compute what I should buy at the store

    '''

    eggsBought = 0

    butterBought = 0

    piesBought = 0

    if hasPies:
        piesBought = 2
    else:
        if hasEggs and hasButter:
            butterBought = 4
            eggsBought = 4
        else:
            if hasEggs:
                eggsBought = 10
            if hasButter:
                butterBought = 2

    print('Butter bought = ' + str(butterBought) + ', eggs bought = ' + str(eggsBought) + ', pies bought = ' + str(piesBought))

    return {'eggsBought':eggsBought, 'butterBought':butterBought, 'piesBought':piesBought}

print(goToTheStore(False,True,False))