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


#1

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
MDN

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?


#2
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
<<=   LEFT SHIFT
>>=   RIGHT SHIFT

These will come in handy once you reach that unit.


How do I use exponentiation in a function?
#3

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!


#4

is there a keyboard shortcut for `

|=    OR

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


#5

No. It takes two keypresses. | and =.


#6

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


#7

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


#8

how do I get that first character?


#9

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


#10

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


#11

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


#12

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


#13

You will need to install Python as an administrator.


#14

Okay, Will do that. Thanks


#16

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