CMPT 120 Lecture 6 – Unit 1 – Chatbots

Slides:



Advertisements
Similar presentations
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
Advertisements

Lecture 11 – if … else, if... elif statements, nested ifs COMPSCI 1 1 Principles of Programming.
An Introduction to Textual Programming
Introduction to Computing Using Python Imperative Programming  what is a Python program?  print() statement  input() statement  type conversion statements.
Flow of Control Part 1: Selection
How to start Visual Studio 2008 or 2010 (command-line program)
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
Variables and Expressions CMSC 201 Chang (rev )
Computer Science 111 Fundamentals of Programming I Making Choices with if Statements.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 21, 2005 Lecture Number: 10.
CSCI/CMPE 4341 Topic: Programming in Python Review: Exam I Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Chapter 3: Branching and Program Flow CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
Python Conditionals chapter 5
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
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.
REVIEW No curveballs this time …. PROBLEM TYPE #1: EVALUATIONS.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 3 Friday 03 Oct 2014 EGR 115 Introduction to Computing for Engineers.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
Python Basics  Values, Types, Variables, Expressions  Assignments  I/O  Control Structures.
Introduction to Programming Python Lab 7: if Statement 19 February PythonLab7 lecture slides.ppt Ping Brennan
GCSE COMPUTER SCIENCE Practical Programming using Python Lesson 4 - Selection.
PYTHON PROGRAMMING Year 9. Objective and Outcome Teaching Objective Today we will look at conditional statements in order to understand how programs can.
CMSC201 Computer Science I for Majors Lecture 03 – Variables
GCSE COMPUTER SCIENCE Practical Programming using Python
CMPT 120 Topic: Python’s building blocks -> More Statements
Topic: Python’s building blocks -> Variables, Values, and Types
Topic: Iterative Statements – Part 1 -> for loop
Week of 12/12/16 Test Review.
Topic: Python’s building blocks -> Statements
Topic: Conditional Statements – Part 1
Control Structures II Chapter 3
COMPSCI 107 Computer Science Fundamentals
Topic: Python’s building blocks -> Variables, Values, and Types
Topic: Conditional Statements – Part 2
Selection and Python Syntax
Decisions Chapter 4.
Introduction to Programming
Topic: Functions – Part 2
Variables, Expressions, and IO
UMBC CMSC 104 – Section 01, Fall 2016
CSC115 Introduction to Computer Programming
CSc 110, Spring 2017 Lecture 8: input; if/else
Imperative Programming
Introduction to Programming
Learning to Program in Python
Exception Handling.
CSc 110, Autumn 2016 Lecture 9: input; if/else
Escape sequences: Practice using the escape sequences on the code below to see what happens. Try this next code to help you understand the last two sequences.
Introduction to Programming
Comparing Strings Strings can be compared using the == and != operators String comparisons are case sensitive Strings can be compared using >, =, and.
Python programming exercise
The first number is posted telling what random number was selected, I did this for testing purposes, in the real thing it would not be there. Since the.
Python Basics with Jupyter Notebook
CHAPTER 5: Control Flow Tools (if statement)
Introduction to Programming
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.
Topic: Iterative Statements – Part 2 -> for loop
Lecture 7 – Unit 1 – Chatbots Python – For loops + Robustness
CMPT 120 Lecture 4 – Unit 1 – Chatbots
CMPT 120 Lecture 13 – Unit 2 – Cryptography and Encryption –
Imperative Programming
Lecture 5 – Unit 1 – Chatbots Python – More on Conditional statements
Lecture 17 – Practice Exercises 3
Lecture 20 – Practice Exercises 4
Lecture 20 – Practice Exercises 4
Lecture 17 – Practice Exercise 3 SOLUTIONS
IST256 : Applications Programming for Information Systems
Data Types and Expressions
Presentation transcript:

CMPT 120 Lecture 6 – Unit 1 – Chatbots Python – More on Conditional statements and Boolean Expressions

Homework Show Case Problem Statement Write a chatbot that prints random cookie fortune statements # Fortune Cookie # Gives a random fortune # Date: 5/15/19 import random # First gives a prompt to break the cookie. cookie = input("Hello there, press enter to break this cookie.") # This is the list of possible fortune given by the cookie. fortune = ["Gift of Luck", "Gift of Love", "Gift of Power", "Gift of Misfortune", "Gift of Friendship"] # this random chooses from the list of fortunes luck = random.choice(fortune) # prints the outcome print(luck) Thank you for sharing your link

Review from last lecture What is wrong with this Python code fragment? https://repl.it/repls/OverdueSadBackup # Say How is it going? and get user's reply reply = input("How is it going? ") # Say Glad to hear if the user is doing well if reply == "Awesome!" : print("Glad to hear!") else: # And Sorry things are not going well! otherwise print("Sorry to hear things are not going well!")

Review from last lecture What is wrong with this Python code fragment? Note the usefulness of the comments! https://repl.it/repls/InconsequentialMelodicConference # Chatbot asks How old are you? age = input("How old are you? ") # If the user is old enough to drink ... if age >= 19 : # Chatbot suggest an alcoholic drink. print("How about a beer?") else : # Otherwise, a non-alcoholic drink. print("How about a Shirley Temple?")

Conversion functions int( ... ) -> convert into an integer float( ... ) -> convert into a floating point number str( ... ) -> convert into a string Example gradeMT = float(input("Please, enter MT grade: "))

Review Input function input( ) or input( prompt ) How it works: The prompt is printed on the screen The user enters the requested data then presses Enter This data is returned from the function input( ) into our program as a string GPS: When prompting the user, we must give her/him clear and unambiguous instructions: Description of what to enter: Enter your name: Example of values to enter: (yes/no) The format of this value (if possible) The range of the value: Enter a number between 1 and 10: etc...

GPS related to input and output statements and user interaction From a user perspective, i.e., from the perspective of the person typing her/his name, which user interaction would we prefer? User interaction #1 or User interaction #1 Why? User interaction # 1 User interaction # 2

Last Lecture, we did … 1. Fortune Cookie Generator : https://repl.it/repls/RuddyIdealApplets 2. How's it going? Chatbot - version 1 (if/else) https://repl.it/repls/BusyOnerlookedIteration 3. How's it going? Chatbot - version 2 (if/elif/else) https://repl.it/repls/DefensiveVeneratedMicrobsd 4. How's it going? Chatbot - version 3 (if/elif/elif/else) https://repl.it/repls/DopeyVitalApplicationprogrammer 5. How's it going? Chatbot - version 4 (if/elif/else and compound condition using “or”) https://repl.it/repls/MushyFaroffQuadrants

Review from last lecture Do these 2 Python code fragments produce the same result? A B grade = 78 if grade < 60 : print("F") else : if grade < 70 : print("D") if grade < 80 : print("C") if grade < 90 : print("B") print("A") grade = 78 if grade < 60 : print("F") elif grade < 70 : print("D") elif grade < 80 : print("C") elif grade < 90 : print("B") else : print("A")

Review from last lecture Do these 2 Python code fragments produce the same result? B C grade = 78 if grade < 60 : print("F") elif grade < 70 : print("D") elif grade < 80 : print("C") elif grade < 90 : print("B") else : print("A") grade = 78 if grade < 60 : print("F") if grade < 70 : print("D") if grade < 80 : print("C") if grade < 90 : print("B") else : print("A")

Hand Tracing What is it? Why doing it? When a software developer manually goes through her/his code (program) and “execute” it as if s/he was a computer, mimicking the Python Interpreter Why doing it? To figure out what our program does/produces, hence to verify whether our program is solving the problem To determine whether our program contains any errors

Little Exercise – Version 1 if condition 1 : if condition 2 : some statements A if condition 3 : some statements B else : some statements C if condition 4 : some statements D some statements E some statements F some statements G

Little Exercise – Version 2 if condition 1 : if condition 2 : some statements A if condition 3 : some statements B else : some statements C if condition 4 : some statements D some statements E some statements F some statements G

Homework Problem Statement Write a login program, which allows a user to login in with a password

Examples of Boolean

Next Lecture Let’s build a simple game! Problem Statement Write a guessing game, which allows a user to guess a number between 1 and 10 Wouldn’t it be nice to play our guessing game many times without having to press Run over and over again?