Can you please confirm if the psuedocode I propose for adding python variables is correct?


Please leave the following link in the post so we can find the unit module, else replace it with a link to the exact lesson:

operator lesson

useful links

So I wanted to make sure that I am reading the following example in the correct way:

money_in_wallet = 40
sandwich_price = 7.50
sales_tax = .08 * sandwich_price

sandwich_price += sales_tax 
money_in_wallet -= sandwich_price

So this is the example and will not give me the answer to the final problem but for understanding reasons I am trying to make sure I can read it correctly - so look at the last two lines.

jumping to mdn (the link provided) this is what addition assignment looks like:
// Assuming the following variables
x = 5
y = 10
z = 25
// Number + Number -> addition
bar += 2 // 7

Now back to my example:
are you adding the proportion of sales tax (7.50*0.08) to the actual sandwich price?
Are you subtracting sandwich price from money in wallet?

x += 2     # 7

In Python, # is an inline comment. // is the math operator for floor division.

All basic arithmetic operators can be combined with the assignment operator, =.

+=    addition
-=    subtraction
*=    multiplication
/=    division
%=    modulo
//=   floor division
**=   exponentiation

The compound assignment is also possible with bitwise operators…

&=    AND
|=    OR
^=    XOR

These will come in handy once you reach that unit.

How do I use exponentiation in a function?

As far as your example goes - to answer the last two questions you asked - Yes. You are adding the proportion of sales tax to the price of the sandwich, making the new variable equal to that of (7.50 + (7.50 * 0.08)). The reason these are separate are to leave room in a larger program for multiple items with a sales tax calculated in. For the second question, yes as well. The program is saying that NOW, money_in_wallet is equal to itself minus sandwich_price. Hopefully this helped, Cheers!


is there a keyboard shortcut for `

|=    OR

I am talking about specifically that I looking symbol. Do I just use I?


No. It takes two keypresses. | and =.


is that first one an I and the second one an equals sign?


Yes, the first character is a pipe. |= is the bitwise OR assignment. Not to be confused with the logical or operator.


how do I get that first character?


It’s usually near the Enter (Return) key, shifted backslash. On laptops it might be in the number key row at the right end.


Please if I type my python programming codes using like say notepad how do I run it. Thanks


You won’t be able to run it on your machine without Python installed. One could use REPL.IT to run and test it.


Thanks. I’m using windows7 and the python I downloaded and tried to install couldn’t. What could be wrong


You will need to install Python as an administrator.


Okay, Will do that. Thanks


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