Thank you. I fixed it.
Hi, I understand what it’s looking for and completed the exercise, I just don’t fully understand why if x=5 and you’re updating that to a new value of x=x+5 why it’s not 5=5+5. Why does the second x in the equation retain the last value for x, but the first one doesn’t?
x+5 evaluates to
5+5, which evaluates to
10, which is then assigned to the variable on the left, which is
Does that help? I think maybe the tutorial needs to explain more thoroughly that the various symbols do not have quite the same meaning as in mathematics.
In addition to what @Scott_McNay has explained, it may be useful to walk through each element as if we are talking to the computer. So let’s break it down:
x = : this part is telling the computer that we want to assign a new value to
x. Whenever you see the
= symbol it means that the variable (or identifier) on the left is going to be assigned a new value.
x + 1 : this is on the right side of the assignment symbol, meaning it is the new value that will be given to
x. At this point,
x still has it’s old value. The computer will look ‘up’ to see what
x has been holding to date, and then add 1 to it.
Hopefully this helps!
I put in your solution exactly and I still get errors from your app that I can’t complete this puzzle
Are you still stuck on this puzzle? Make sure you’re using
num for numbers and
str for words. If there are quote marks around a number, then it will be seen as a keyboard character, not an amount.
You can also upload a picture of your code here to get another look.
Hrmm… It is confusing how the language always appears to be mathematical but is actually a combination of directive shorthand and math. Instinctively I look at it and think “x” does not equal “x + 5”… (How is it not a circular reference? Is “x =” of “x = x + 5” happening independently of “x + 5”? Wouldn’t it make more sense to write “x + 5 = x” if the goal is to update the value of x? How does the print function portion know to show the value of x rather than displaying “x”?)
Will be interesting to see how complex math functions are handled later on (if those are in the program). Thanks for your explanation.
EDIT: I see you guys answered my questions above. Sorry, disregard my post
print x will always only ever print the contents of the variable named
print "x" will always only ever print the literal string shown within the quotes: “
The difference is that one has quotes and the other doesn’t.
Each language has it’s own rules. In most modern languages, you can use this:
a = b = 2
to determine if
2 and assign
But, I recall seeing code for what I think was an old mainframe version of BASIC in which the value of
2 would be assigned to the variable
b, then the value of the variable
b (which was now 2) would then be assigned to the variable
As a clarification to future readers:
= is the assignment operator. That means “make one side equal to the other side” (usually, change the left side to match the right side).
===, is the equality operator. That means “check if one side is already equal to the other side”.
a = b = 2 will be interpreted as “set
b to 2, and then set
a to the value of
b which is 2”. Which makes
b have a value of 2. The code
a = b === 2 can be rewritten as
a = (b === 2), and you can break it up into two parts:
b === 2, “Is the variable
bstoring the value 2?”. That is either
a = (either true or false depending on if b was equal to 2)
Here is a chart that lists the order that each operator is executed. If you remember the order of operations and PEMDAS from arithmetic, this is the same thing except with more operators included. You’ll notice that assignment
Flip a Coin explainer
The code you’ve added is fine. The feedback is still looking at the original starter code and asking you to change the numbers from 0 to something else.
If you remove the starter code (the first 5 lines) and keep the code you added, you should pass the puzzle.
It looks you haven’t changed the
x = x - 0 yet. It’s just above the last print statement. You should be able to move on if you change it.
Hope this helps
Im still stick on this. Grrr so frustrating!!
Could you post a screenshot of your code?
Basically I have the same example equation. It looks like this:
X= x + 0;
Print (‘x is’ + x);
X= x - 0;
Print (‘x is now’ + x);
What do I do?
It looks like you have the starter code. In that case, you only need to make 2 changes: turn each 0 into a different number.
If that doesn’t work, try resetting the puzzle using the button, and then try editing the zeros.
print() at the bottom should be using the
x variable instead of the number 7.
Try changing the
x, and be sure to use the variable name
x and not a string
Mine is broke i dis the answer this says to use but grasshopper itself says incorrect format