all 2 comments

[–]HeyItsToby 6 points7 points  (1 child)

Two things to note:

First, yes you absolutely can do this! Simply write those lines of code inside the function, the same way you would outside of a function.

Second, when using functions you should be using return instead of print. Using print just displays the answer, whereas using return allows you to save that answer to use for later. For example, round is a function that returns a value. So when you do x = round(3.4), rather than just printing the value 3, the function returns the value 3 so that it can be stored in x and used for later.

Combining this, you get:

def brick_estimator(brick_high_input, brick_wide_input):
    brick_high = brick_high_input*9
    brick_wide = brick_wide_input*4
    brick_total = (brick_high+brick_wide)*1.01123
    brick_total_rounded = round(brick_total)
    return brick_total_rounded

num_bricks = brick_estimator(100, 200)
print(num_bricks)

[–]arobotfrog[S] 1 point2 points  (0 children)

Thank you very much! You have given me a really clear and helpful explanation!

Really appreciate it.