Is meal reassigned for efficiency?


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-python/lessons/tip-calculator/exercises/reassign-in-a-single-line?action=lesson_resume

<In what way does your code behave incorrectly? Include ALL error messages.>

<What do you expect to happen instead?>
Why reassign meal instead of creating another variable or changing the math?
meal
tax
tip
total

```python

Replace this line with your code.

<do not remove the three backticks above>

#2

At this stage of learning, efficiency is the last thing we need concern ourselves with. That concern comes up way later. Right now the only thing we need to pay any mind to is keywords, syntax and the general concepts like math operations, assignments and such.

meal = meal + meal * tax

The above is the full blown explicit statement expected in the lesson. Later on you will learn how to refine this, but for now just go with it.

meal = meal * (1 + tax)

is the simplified form of the math expression (that your math teacher would expect) but it’s not what the lesson is about.

Ignore the next line (it is the refactored form)

meal *= 1 + tax

As I stated, this will come up later so don’t spend any time on it, just now.


#3

Awesome! Thanks!

I did see the " *= " in a later lesson which caused some confusion at first
but after little digging online found the definition.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.