Beruflich Dokumente
Kultur Dokumente
Lesson 2
www.teachingcomputing.com
Series Overview
Information/Theory/Discuss
Task (Code provided)
Challenge (DIY!)
Suggested Project/HW
*Please note that each lesson is not bound to a specific time (so it can be taken at your own pace)
If
You will often need to create flow charts to show the logic behind
your program.
Can you make any sense
the
following
chart? What is it
Readof
more
about
Flow chartsflow
here: https://en.wikipedia.org/wiki/Flowc
True
trying Ifto
x <say?
y
False
If y <
x
False
Output:
Done
Output x is
less than y
Input x 5
True
Output y is
less than x
Input y 7
Answer 1:
Answer 2:
!= is the
operator for
NOT equal to.
Task 1: Solution
password="open123"
print('Enter password:')
answer=input()
if answer==password:
print("yes")
else:
print("no")
Common errors to
look for.
Challenge 1: Solution
def login():
username="username1"
password="open123"
print('Enter username')
answer1=input()
print('Enter password:')
answer2=input()
if answer1 == username and answer2
print("Access Granted")
else:
print("Sorry, Access Denied")
== password:
def checknumber():
#
#
#
#
Challenge 2: Solution(s)
Challenge 2 Solution
def
gradechecker():
# In this
program, we
input a number
# check if the
number is
positive or
# negative or
zero and display
# an appropriate
message
num =
float(input("Enter
a number: "))
if num > 50:
Extension Solution
Example 1
#Example of
AND
If x < y and x < z:
print (x is less than
y and z)
Example 2
#Non Exclusive
Or
If x < y or x < z:
print(x is less than
either y or z)
Constants
It is worth noting that many of the programs you write will have
CONSTANTS as well as variables. The difference is that constants remain
constant that is they dont change! Examples shown below:
Black and White on the right are in
UPPER CASE and we put them in
like this to signify they are constants.
If you expect a colour to change
during the program execution, then it
should be set, not to a constant, but
to a variable! An example would be
Backgroundcolour!
Variable:
off black)
http://arcbotics.com/lessons/if-statements/
https://www.youtube.com/watch?v=vMHfUWkELg0
https://www.youtube.com/watch?v=II5WTVvryvk