Lesson 3 of 12
Learn variables with flowchart blocks: Ask for an answer, Create a Value to remember something, and Change it as the program runs. Try each one.
About 6 minutes · 4 parts, each with a program to try
Part 1 of 4
Ask shows a question, waits for an answer, and keeps it in a value with a name, like name.
Use the name in later blocks, and the computer puts the answer there.
name"Nice to meet you, " + nameRaviIt showsNice to meet you, Raviname = input("What is your name? ")print("Nice to meet you, " + name)Part 2 of 4
A value is a labelled box that holds a number or some words. Create Value makes one: price = 40.
Programmers call these variables. Once a value exists, any later block can use it.
price = 40count = 3"Total: " + price * countTotal: 120price = 40count = 3print("Total: " + str(price * count))Part 3 of 4
Change Value gives a value something new. score = score + 10 means: take the score, add 10, and keep the result as the score.
Watch the Values tab while it runs to see the box change.
score = 0score to score + 10score to score + 5"Score: " + scoreScore: 15score = 0score = score + 10score = score + 5print("Score: " + str(score))Part 4 of 4
On an Ask block, They type decides what's allowed: A whole number for an age, A number for a price, Words for a name.
Anything else is asked again, so your program never does maths with Ravi as an age.
age"Next year you will be " + (age + 1)12It showsNext year you will be 13age = int(input("How old are you? "))print("Next year you will be " + str(age + 1))Quick check