
Variables: Introduction (Python programming)

Upgrade for more content
True or false? Pseudocode is a programming language.
Pseudocode describes in human language what a program should do. Humans understand it, but computers don’t. We need to translate the code to a language that the computer understands: a programming language. One of them is Python. Here's what Lina's pseudocode looks like: “Ask the user to enter their name” “Note name” “Say hello name” Lina keeps the pseudocode on the screen, to refer to when she writes the Python-code.
To show that these are not instructions for the computer, she writes three quotation marks one after another at the start of the pseudocode and also ends the last row with three quotation marks. Now Lina will translate the first row of the pseudocode: “Ask the user to enter their name” Lina writes the word ‘input’ - which is one of Python’s instructions - followed by a pair of parentheses. Within these parentheses, she writes the text she wants to be shown on the screen. Quotation mark. Input your name.
colon Quotation mark. All within the parentheses. The quotation marks are important. They show that “Input your name” is text to be displayed on the screen. Oh, look, Lina is testing her code, and there is the text on the screen.
And now the program waits for the user to write their name. That was the first row in the pseudocode! The second row is ‘note name’. Which means: Tell the program to save what the user writes. Lina does that using something called a variable.
She creates a variable called ‘name’, by writing: name equals. Every time a user enters their name it is saved as the variable: name. Now, how should Lina translate the next line into Python? “Say hello name” She uses the instruction print followed by parentheses. Inside these parentheses she will write what should be output. She writes: “Hello” within quotation marks, then a plus sign to show that she will add something: the variable name.
Now she tests the code. Lina writes her own name, and presses enter. Then the computer outputs: “Hello Lina”. It worked! She has translated the pseudocode into Python-code.
If Lina wants the program to ask more questions, such as, “What is the user's favourite subject in school?” How would she do that? Pause the video and think. Have you figured it out? Lina creates another variable, which she calls ‘subject’ and assigns it a value using this code: equals input parenthesis Quotation mark What is your favorite subject in school? Quotation mark and end parenthesis.
Now she adds yet another instruction: “print”. Within these parentheses she writes the text, “Oh, you like..” followed by a plus sign and the variable ‘subject’. Now Lina is going to see if the code works. She writes her name. She presses “enter”.
And writes her favourite subject... Maths and presses ‘enter’ again. And the program outputs: “Hello Lina! Oh, you like maths.” Good it works. Now you can try getting the program to ask even more questions.