Introducing Python: Writing A Python Program
Introducing Python: Writing A Python Program
Decisions
We have just used an if / else to allow our program to make a simple decision about what to
say. The lines that begin with if and else must end in a colon symbol “:” and the instructions that
we want to be done after the “if” and “else” must be indented!
Project 2:
Python decision programs
Program Recipes: Turing Chat Bot.
1. We are going to use some basic Python 2. Decide what topics your chat bot is going
coding instructions that could be used to to talk about and use prints, inputs and
make a “chat bot”. These instructions are variables to allow it to start responding. Our
called if, elif, else. example chat bot program begins like this :
In computing these methods are known as
selection .
5. Your program now can ask two questions; “who are you?” and “what is your hobby?” and
can make responses based on what is typed in.
Use these methods to make your program ask even more chat questions and give responses
to answers.
6. It's also possible to make more complicated decisions based on values stored in multiple
variables. For example, our program so far has 2 variables called name and hobby. We can
use operators like “and” and “or” to make more complex decisions.
if name == “Wayne” and hobby == “football”:
print(“Hey! Are you Wayne Rooney from Manchester United?”)
Now try using all these methods to make a chat bot that could fool someone into thinking
they were chatting to a real person!