Session 1.1 Get Start With Python
1.1 what is coding
- Computer programming, or coding is writing script using the language that computer can understand.
- Coding is fun.
- You can give order to computer
- You can build a game
- Coding is using Computer to solve problems.
- Coding is a crucial skill every kids should learn.
- Coding is a valuable job skill for your future
1.2 What is Python
- Python is real programming language
- Compare to Scratch
- Python is Easy to Understand
- Read like English
- Python is the most popular and growing language
- Python is best for beginner and for people who is not professional programmer to do coding.
- Python is good for small project
- Python is weak type language compare to C++, C# or Java
1.3 Install Python
- Go to Python download page, download and install Python 3.8 and up
- How to Install Python
1.4 Install a Python Editor
-
Python IDLE
- PyCharm
- PyCharm Edu is a python editor help you learn Python
- Click to download pyCharm Edu
- VsCode
- VsCode is a editor for many different programming language.
- Click to download VsCode
- How to install VsCode for python
- Getting Started with Python in VS Code
1.5 Your first python code
-
Hello World example
# hello_world.py print("Hello world!") name = input("What is your name?\n") print("Hi,", name)
Open a Editor, input upper lines, save as file hello_world.py
in terminal, input hello_world
to run it.
or in editor menu click the run
button.
1.6 Drawing with python Turtle
1.6.1 Drawing a line with python Turtle
In your Python editor, create a new file and name it as MyFirstTurtle.py
# Code sample MyFirstTurtle.py
import turtle,time
# Draw line with length 100
turtle.forward(100)
# waiting 10 sec and exit python running window
time.sleep(10)
Notice the time.sleep(10) is used for terminal that will close after python script finished. If you use IDLE it will not necessary.
1.6.2 Make turn and draw another line
please add below code before time.sleep()
of code in 2.1
# make turn 90 degree and draw another line
turtle.left(90)
turtle.forward(100)
1.6.3 Continue and draw a square
Repeat the code in 2.2 twice, you could get a square.
Below example, in stand of using turtle
directly, I chose use a turtle.Pen()
instance.
# Code sample MyFirstTurtle.py
import turtle,time
t = turtle.Pen() # make a turtle Pen instance.
# Draw line with length 100
t.forward(100)
# make turn 90 degree and draw another line
t.left(90)
t.forward(100)
# continue turn and drawing line twice
t.left(90)
t.forward(100)
t.left(90)
t.forward(100)
# waiting 10 sec and exit python running window
time.sleep(10)
1.6.4 if you make a right turn
Turtle left turn command is t.right()
. Please try to drawing lines like below image:
1.6.5 Make Another turtle
With below code, you could multiple turtles, please try and see how it works
import turtle
t1 = turtle.Pen()
t2 = turtle.Pen()
t1.right(90)
t2.left(90)
t1.forward(100)
t2.forward(100)
1.6.6 More about Turtle
Please check the document of Turtle Graphics https://docs.python.org/3/library/turtle.html