CMPT 120 Lecture 4 – Unit 1 – Chatbots

Slides:



Advertisements
Similar presentations
ECS 15 if and random. Topic  Testing user input using if statements  Truth and falsehood in Python  Getting random numbers.
Advertisements

Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Python (yay!) November 16, Unit 7. Recap We can store values in variables using an assignment statement >>>x = We can get input from the user using.
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
Lecture 2: Variables and Expressions Yoni Fridman 6/29/01 6/29/01.
Introduction to Python
Lecture 2 - Variables, program execution, calculations, print() COMPSCI 101 Principles of Programming.
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
An Introduction to Textual Programming
JavaScript – Part II Data Types and Operations George Mason University June 3, 2010.
Programming.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
CS1022 Computer Programming & Principles Lecture 1.2 A brief introduction to Python.
Chapter 2 - Algorithms and Design
An Overview of Programming in Python CSC 161: The Art of Programming Prof. Henry Kautz 9/9/2009 Slides stolen shamelessly from Dr. Mark Goadrich, Centenary.
General Computer Science for Engineers CISC 106 Lecture 04 Dr. John Cavazos Computer and Information Sciences 09/10/2010.
Python Jim Eng Vote on class policy In lecture we discussed several ways in which you might show credits for content in the web pages.
Agenda Review C++ Library Functions Review User Input Making your own functions Exam #1 Next Week Reading: Chapter 3.
Lesson 4 Using Variables in Python – Creating a Simple ChatBot Program.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
Course A201: Introduction to Programming 09/16/2010.
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
Variables and Expressions CMSC 201. Today we start Python! Two ways to use python: You can write a program, as a series of instructions in a file, and.
Python Let’s get started!.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Creating a mystic meg program A simple program asking the user questions and using their answers to build up a fortune telling in a list.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Quiz 1 A sample quiz 1 is linked to the grading page on the course web site. Everything up to and including this Friday’s lecture except that conditionals.
Chapter 3 Using Variables, Constants, Formatting Mrs. UlshaferSept
CMSC201 Computer Science I for Majors Lecture 07 – While Loops
CMSC201 Computer Science I for Majors Lecture 03 – Variables
Introduction to Decision Structures and Boolean Variables
CST 1101 Problem Solving Using Computers
Whatcha doin'? Aims: To start using Python. To understand loops.
Topic: Python’s building blocks -> Variables, Values, and Types
Topic: Functions – Part 1
CS1022 Computer Programming & Principles
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Week of 12/12/16 Test Review.
Python Let’s get started!.
Topic: Python’s building blocks -> Statements
Topic: Python’s building blocks -> Variables, Values, and Types
ECS10 10/10
Topic: Functions – Part 2
Variables, Expressions, and IO
Python - Functions.
Engineering Innovation Center
Fill the screen challenge!
And now for something completely different . . .
T. Jumana Abu Shmais – AOU - Riyadh
We’re moving on to more recap from other programming languages
Coding Concepts (Basics)
Introduction to TouchDevelop
Testing and Repetition
Section 1 Introduction To Programming
A look at Python Programming Language 2018.
Class 2.
Flowcharts and Pseudo Code
Variables & getting info from the user
Python Basics with Jupyter Notebook
CSE 231 Lab 2.
CMPT 120 Lecture 2 - Introduction to Computing Science – Problem Solving, Algorithm and Programming.
CMPT 120 Lecture 3 - Introduction to Computing Science – Programming language, Variables, Strings, Lists and Modules.
CMPT 120 Lecture 15 – Unit 3 – Graphics and Animation
CMPT 120 Lecture 6 – Unit 1 – Chatbots
CMPT 120 Lecture 13 – Unit 2 – Cryptography and Encryption –
Lecture 5 – Unit 1 – Chatbots Python – More on Conditional statements
Lecture 20 – Practice Exercises 4
Presentation transcript:

CMPT 120 Lecture 4 – Unit 1 – Chatbots Python - Conditional statements (Branching)

Review from last lecture Name of our program Algorithm steps https://repl.it/repls/SpectacularDeeppinkVaporware

Review from last lecture Output Assigning a value to a variable Input Using a variable Concatenation https://repl.it/repls/GrossElementaryApplicationprogram

Review from last lecture Prompt A space A space Function Argument https://repl.it/repls/ShoddyHollowUnix

About variables There are some constraints to how you can name your variables, e.g. Can contain letters, numbers, and underscores Should start with a letter (lowercase, by convention) They can't contain spaces or symbols They can't be one of the reserved keywords (see below for list) http://interactivepython.org/runestone/static/thinkcspy/SimplePythonData/VariableNamesandKeywords.html

GPS -> Good Programming Style Give your variables descriptive name Why? We shall record everything we say in class about Good Programming Style on a web page accessible from the menu of our course web site Check this web page out by clicking on the menu option Good Programming Style (GPS)

Your turn! Problem Statement: Write a chatbot that can say hi and learn your name and … After the greetings, make the chatbot ask what your favourite music band is, and let you respond Then, the chatbot makes a comment about your response (but it cannot simply repeat what you have just said!)

Don’t forget to … Update your algorithm -> comments Translate them into Python Test your program

Let’s review some concepts How do you print in Python? What is the command or function to get input from the user? How do we call the string that is used as an argument to the function input()? An argument is what is put inside the () of a function. How do you concatenate two words (strings) in Python? How do you store an input from the user? This allows your program to remember data. What symbol do we use to assign a value to a variable?

Let’s introduce Python Lists and Modules Problem Statement: Write a chatbot that can say hi and learn your name and … After the greetings, make the chatbot ask what your favourite music band is, and let you respond Then, the chatbot makes a comment about your response This comment should not be too obviously repetitive Hum… what do you mean?

Let’s create another chatbot! Problem Statement: Write a chatbot that prints random cookie fortune statements

Let’s review some more concepts How do we make a list in Python? What module do we need to import to randomly choose something from a list? How can we test smaller pieces of our Python code? What is concatenation? What does a dot after a module name do? What is the only kind of symbol we can have in a variable name?

Let’s introduce Branching (Python Conditional statements) Problem Statement Make a chatbot that asks a user how their day is going, and make a comment that changes depending on how the user answered Also think about the various branches in web sites. If you say YES, then continue with your purchase. If you click CANCEL, you’re back to a different path. Good! How’s it going? Not great...

Your turn! Problem Statement Modify the How's it Going chatbot to use 2 "elif" statements

Review: Conditional statement if <boolean expression>: ... elif <boolean expression>: else: The only thing required in a conditional Optional. Can be repeated Optional. You can only have one else per if

Let’s review some concepts What does a conditional statement do? Is the if part of a conditional statement mandatory? Is the else part of a conditional statement mandatory? What values can a Boolean expression produce? What is wrong with this code fragment? if color = "purple": print("Cool!")

Next Lecture We’ll continue practicing using conditional statements in our Python programs