BasicCoding1.0 2
BasicCoding1.0 2
BASIC CODING
1.0For Ages 9 - 12
Lesson 1: Printing Text on the Screen
Print shows text on the screen. When you want something
shown, you enter the command “print” to display it.
print(“hello”)
hello
Entering this in the
program will print
hello on the screen
Try It!
VSCode
x = input()
x is 10 OK
earlier that
x is 10
stored in x.
Try It!
Step 1 Open https://repl.it in your browser, create
new repl (select python).
y = input()
Exercise
y to x and printing the input.
nameofperson = input()
stored in nameofperson.
You can type two lines in a single program. You can have
personsname = input()
firstname = input()
from = input()
Result:
name1 = input()
name2 = input()
Advanced Exercises
multiple times.
Exercises
def do_something():
print(“Hello, my name is ”)
print(“John Student!”)
The name of the function is the word after the ‘def’, in this
case do_something. If you write do_something() in your
code, it will instantly call the function.
do_something()
Result:
Hello, my name is
John Student
Try it!
def print_names_of_places():
print(“London”)
print(“Lagos”)
print(“Lima”)
def print_names_of_animals():
print(“Ladybird”)
print(“Lion”)
print(“Lizard”)
print_names_places()
print_names_of_animals()
Exercise
def print_this_name(name1):
x = “John”
print_this_name(x)
Run the code. Look at the output and try to understand how
it worked.
Exercise
print(first_name)
print(middle_name)
print(last_name)
Exercise
statement.
x = input()
if x == “hello”:
print(“hi”)
if x == “hi”:
print(“hello”)
Exercises
return x + y
z = add_these_text(“Hello”, “World”)
print(“The answer is “ , z)
Exercise
Exercise
x = True
y = False
if x == True:
print(‘X is True’)
if x:
print(‘X is True’)
if y:
Exercise
print(x)
Result:
The code will repeat itself three times,
0 1 2
each time increasing the value of x.
Exercise
What happens if you are in a loop and you want to end the
loop? You use the break keyword.
print(str(x))
if x == 10:
break
The loop is set up to run to 20, but the break will make it
end once it reaches 10.
Exercises
You can also use the while loop for this. Search on
Google for ‘python while loop’ to research about this
type of loop.
x now contains a list of all those cities. You can loop over all
items in the list and output them.
for y in xlist:
print(y)
Module with
Module that
password
reads user
checking input
import password
def check_pass():
s = input()
x = password.check_pass()
if s == “secret”:
if x == True:
return True
print(“Pass Correct”)
else:
else:
password.py myapp.py
import nameoffile
This will make all the functions in the file available. You
reference them by using nameoffile.function_name.
Exercise
Exercise
Exercise
Last Exercise
contact.