LeaRn To CodE
Write your code on the left hand side window on the editor below and hit the “RUN”- button. Your code result will show on the right hand side window.
- Be careful to type exactly as in the example including any commas, quotation marks, letter case etc.
- Start typing from the beginning of each line.
- Press enter to move to next line of code.
- If you code shows a pink line, it means there is an error on the code. Just try again and when you get it right the pink line will disappear.
Follow the tabs below to start coding! Use computer or tablet instead of mobile phone.
1.
2.
3.
4.
5.
6.
7.
8.
9.
1.
print(2)
and press RUN- button. Did you manage? You just wrote you first ever code! Well done!
2.
print(2 + 2)
You’ve just created a simple calculator!
You can try these different calculations;



You can also try really complicated calculations. See how quickly your computer can calculate them!
3.
print(“Hello”)
Quotation marks tells the computer, that something is text instead of numbers. Try printing some other words or sentences.
4.
print(3 * “Ha”)
Why do you think the code did that?
5.
text = “I love coding!”
print(text)
What happened??
You’ve just created and used a variable! A variable can be used like a post-it note where you write your words or numbers. Then you can stick the post-it note anywhere you might need it in your code without having to write the words or numbers again.
You can name your variable almost anything you like, but be sure to write it exactly the same way when you use it in your code.
Handy hey?!
6.
yummy = “chocolate”
print(“I love”, yummy)
You can try typing you own favourite treat instead.
7.
Let’s try something a bit more complicated. Write this code to your Python code editor and find out what it does.
name = input(“What is your name? “)
print(“Hello”, name)
Then “Run” the code. You can see the question appearing on the print out screen. Click at the end of the question where you see a little grey box, type your name and press Enter-key. What happened?
You just used an input command to give your code information. Well done!
8.
X = int(input(“Give first number: “)
Y = int(input(“Give second number: “)
sum = X + Y
print(sum)
Remember to click on the grey box, type any number and press Enter-key. Repeat for the second question. What happened?
int() command asks the computer to change our input to numbers. Otherwise it is not able to calculate.
You can change the calculation by replacing the plus + with minus – , divide / or multiply *. Try it!
9.
Now you can try writing your own codes using what you have just learnt. Test different things and have fun!