Preview lessons, content and tests

Computer Science & Programming solved. All in one platform.

1. To trial the platform and take tests, please take a few seconds to SIGN UP and SET UP FREE.

2. Searching for something specific? See our text overview of all tests. Scroll right for levels, and lists.

3. Student and Teacher User Guides |  Schemes of Work |   Real Teacher use Videos |


Join 36000+ teachers and students using TTIO.

IF ELSE Statements - making decisions

So far, we haven't been able to do anything conditionally; we cannot tell Python "do this in some cases and do this other thing" in others. This is the sort of logic we really need and indeed we use it all the time in making every day decisions!

Programming languages like Python have tools to mimic those real-world choices.

Many of the decisions we make throughout the day – "it's raining - get an umbrella"; "I have a cough - uh oh, maybe I need to call in sick"; "If my tummy rumbles, I'll head to the fridge" – have an if-then structure. Just like you, Python can make if-then decisions.

If statements

If statements are how you direct Python to do something if something else is true. For example – run the code below. What do you think it'll do?

Code

If the user enters the right secret code (007) then access is granted, else denied.

#Cut and paste the code below into this trinket
code=input("Enter secret code:")
if code=="007":
  print("Access Granted")
else:
  print("Impostor. Sorry, goodbye!")

Trinket

www.teachyourselfpython.com