0% found this document useful (0 votes)
22 views2 pages

Introducing Python: Writing A Python Program

This document introduces how to write a basic chatbot program in Python using conditionals like if/elif/else statements. It provides an example chatbot program that asks for a user's name and hobby, and prints different responses based on the user's hobby input. It encourages the reader to expand the program by asking more questions, giving more responses, and using operators like "and" and "or" to make more complex decisions based on multiple variables. The overall goal is to use these Python programming concepts to create a basic chatbot that could simulate a conversation.

Uploaded by

蕭櫂賢
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

Introducing Python: Writing A Python Program

This document introduces how to write a basic chatbot program in Python using conditionals like if/elif/else statements. It provides an example chatbot program that asks for a user's name and hobby, and prints different responses based on the user's hobby input. It encourages the reader to expand the program by asking more questions, giving more responses, and using operators like "and" and "or" to make more complex decisions based on multiple variables. The overall goal is to use these Python programming concepts to create a basic chatbot that could simulate a conversation.

Uploaded by

蕭櫂賢
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Introducing Python

Writing a Python program.


In IDLE, choose File → New File.

Add some input, print


instructions and a
variable to your
program. Make a
program that asks
for the user's name
and then greets the
user.

Now make your


program capable of
carrying out a
decision based on
what input the user
provides. We are
going to make our
program print a
comment that
depends on what
hobby the user has.

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 .

4. Make sure you use double equals 3. Our example program:


(==) to check what the variable name = input("Hi! Who are you? ")
hobby contains. print ("Pleased to meet you " + name)
Make sure you remember to put a hobby = input ("What is your hobby? ")
colon (:) at the end of the if and if hobby == "coding":
else lines. print("Hey! That's my favourite hobby too.")
The instructions that get carried out elif hobby == “baseball”:
after “if”, “elif” or “else” should be print(“Hey that's a fun sport!”)
“indented” else:
print("I dont know what " + hobby + " is")

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!

You might also like