Introduction
Congratulations! You clicked on a link to something a lot of people consider to be well beyond their ability. Rumours of complex maths, arcane syntax and a host of other scary things put people off attempting to learn to code. This is a shame because even an idiot can learn to code. I am a living example of that.
My goal here is to prove that if you can write a sentence, you can code. In fact, that last sentence was practically code in itself! a = "Can write a sentence" b = "Can write code!" c = "Can't write code!" if a == "Can write a sentence" then print(b) else print(c) end
If you want to try this for yourself, you can go to the web-page here and type this into the box on the left, and then click 'execute'. If you type it exactly as shown (or cut-and-paste like a stinky cheater), you'll see the result:
"Can write code!" If you tried that out, then you've proven my point: you just wrote code, you didn't die, and your brain didn't explode. Congratulations! So What is Coding?
Coding is much like baking. You take ingredients, do stuff to them in a defined order, and end up with (something hopefully similar to) a cake. In the case of coding, those 'ingredients' are data: keyboard input, joystick buttons, text, an image, or anything else. Likewise, the output can be anything you want: a song, a game, or a piece of text.
Ingredients/Variables
In the example above, we had the line:
a = "Can write sentence" The 'a' is a 'variable'. It's like a label on an ingredient box that can contain anything at all. We use variables to store data and then perform operations on that data to get outputs we want. The '=' sign pushes the words "Can write a sentence" into the ingredient box labelled 'a'. After this, 'a' contains the words "Can write sentence". If we had typed: a = 10 ...then the variable 'a' would contain the number 10 rather than "Can write a sentence". A variable doesn't care what it contains. The variable is just a label. If you used a shoe-box and labelled it 'old DVDs' the world wouldn't end if you decided to fill it with socks, even though you might be confused on the day you move out. Also note that, like any label, what we chose as a label for the variable was entirely arbitrary. The letter 'a' has no significance at all. We could have written this instead: hedwig = "Can write sentence" The computer doesn't care what we name things (unless the name clashes with something else). We're just creating a label so that when we want to do something to that variable/data, we can refer to it in a sensible way. In this case... print(hedwig) ...will output "Can write a sentence" because we previously 'assigned' (filled) the box labelled 'hedwig' with those words. Note that it does not output the word hedwig, because the computer only cares about the contents of the data with that label, not the label itself. Conclusion
Today, you learned about variables (the ingredients of your code).
Next time we'll learn how to do more things with those variables. I hope this was simple and informative and that you'll join me for the next one! Good luck and ask any questions you want here.
2 Comments
Mark
4/6/2022 09:37:08 am
As an aside - is it worth adding that if you use quotes within the print brackets (or whatever they are called), so print("hedwig") it would then print hedwig
Reply
Mark again
4/6/2022 09:41:08 am
ahhhh - chapter 3 ;)
Reply
Leave a Reply. |
AuthorFluttermind’s director, Dene Carter, is a games industry veteran of over 25 years, and co-founder of Big Blue Box Studios, creators of the Fable franchise for the XBox and XBox 360. Archives
April 2022
Categories |