Reading Python Code Students will identify the parts of a Python program Students will describe the history of the computer bug. Students will look at.

Slides:



Advertisements
Similar presentations
P5, M1, D1.
Advertisements

Debugging Introduction to Computing Science and Programming I.
Debugging CMSC 201. Announcements Hw2, Hw3 grades returned if something doesn’t seem right, ask Midterm next Thurs (Oct 23) we’ll review on Tues no hw.
Chapter 3 Planning Your Solution
Computing Theory: BBC Basic Coding Year 11. Lesson Objective You will: Be able to define what BBC basic is Be able to annotate BBC basic code Be able.
Algorithm & Flowchart.
Chapter 1 Pseudocode & Flowcharts
Solving Inequalities.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
Eliza the Chatterbox Year 9 Computing HLA
Noadswood Science,  To know the basics of Python coding and decoding Monday, September 07, 2015.
ICAPRG301A Week 4Buggy Programming ICAPRG301A Apply introductory programming techniques Program Bugs US Navy Admiral Grace Hopper is often credited with.
General Programming Introduction to Computing Science and Programming I.
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
Documentation and Comments. What’s a comment? A comment is a simple form of documentation. Documentation is text that you the programmer write to explain.
By the end of this session you should be able to...
Computer Science: A Structured Programming Approach Using C1 2-7 Input/Output Although our programs have implicitly shown how to print messages, we have.
Lesson 4 Using Variables in Python – Creating a Simple ChatBot Program.
Linear Equations, Inequalities, and Absolute Value - Graphing Solution Sets On a Number Line As we saw with the absolute value equations, we could get.
End of unit assessment Challenge 1 & 2. Course summary So far in this course you have learnt about and used: Syntax Output to screen (PRINT) Variables.
Software Development. Software Development Loop Design  Programmers need a solid foundation before they start coding anything  Understand the task.
Debugging, Escape Command, More Math. It’s your birthday!  Write a program that asks the user for their name and their age.  Figure out what their birth.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Calculator Program Explained by Arafa Hamed. First Designing The Interface Ask yourself how many places are there that will be used to input numbers?
Python Lesson 2.
COMPUTER PROGRAMMING Year 9 – Unit 9.04 Week 3. Open the Python INTERPRETER Can you use the interpreter to solve these maths problems? 156 add
GCSE Computing: Programming GCSE Programming Remembering Python.
Learning Objective To be able to… Understand flow chart symbols Complete and correct flow chart algorithms Create a program based on a flow chart.
Controlling Program Structures. Big Picture We are learning how to use structures to control the flow of our programs Last week we looked at If statements.
Functions. What is a Function?  We have already used a few functions. Can you give some examples?  Some functions take a comma-separated list of arguments.
Learning to use a ‘For Loop’ and a ‘Variable’. Learning Objective To use a ‘For’ loop to build shapes within your program Use a variable to detect input.
1 Sections 3.3 – 3.4 Terminal I/O and Comments Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Few More Math Operators
Basic concepts of C++ Presented by Prof. Satyajit De
Software Development.
Understand Problem Solving Tools to Design Programming Solutions
Introduction to Computing Science and Programming I
A Python Tour: Just a Brief Introduction
Topic: Python’s building blocks -> Statements
IF statements.
Topic: Functions – Part 2
Variables, Expressions, and IO
While Loops Chapter 3.
User Defined Functions
Learning to Program in Python
Learning to Program in Python
Procedures Programming Guides.
Learning to Program in Python
Solving Inequalities.
Fill the screen challenge!
Introduction to pseudocode
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
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.
Design and Implementation
Python 21 Mr. Husch.
Inputs and Variables Programming Guides.
CSc 110, Spring 2018 Lecture 5: Loop Figures and Constants
A LESSON IN LOOPING What is a loop?
Loops and Simple Functions
PQA Assessing Program Quality
Introduction to Python
Common Core Math 8 India Walton
WJEC GCSE Computer Science
What you need to do… Drag the pieces of code into the correct order like you can see in the EXAMPLE below. print ( “ int input ) = + Hello world chr ord.
Primary School Computing
Variables, Constants, Assign.
Starter Look at the hand-out.
Lecture 20 – Practice Exercises 4
Presentation transcript:

Reading Python Code Students will identify the parts of a Python program Students will describe the history of the computer bug. Students will look at debugging techniques and classifying errors. Students will compare different kinds of errors

Comments are a note to the humans reading the code. # Eliza-like program def interview(questions): responseNumber = 0 # start with the first response userResponse = input( "? " ) # ask the person to type an answer while ( not "bye" in userResponse): print('\n\n' + questions[ responseNumber ] + " "+ userResponse ,end="") userResponse = input( "? " ) responseNumber+=1 if responseNumber==len(questions): responseNumber = 0 def main(): print('Welcome, I am concerned about you and have a few questions. You can leave by saying "bye".') print("Something seems to be troubling you. How do you feel",end="") responses = [ "Interesting,Let's dive deeper.\nWhat other feelings come to mind when you think about feeling", "Really, how did you feel before you felt", "I wonder, do you think a lot about how you used to feel" ] interview(responses) # call the interview function using the responses defined above Comments are a note to the humans reading the code. They can explain what is going on or describe the parts of the program.

Cross out all of the comments. The computer ignores them. # Eliza-like program def interview(questions): responseNumber = 0 # start with the first response userResponse = input( "? " ) # ask the person to type an answer while ( not "bye" in userResponse): print('\n\n' + questions[ responseNumber ] + " "+ userResponse ,end="") userResponse = input( "? " ) responseNumber+=1 if responseNumber==len(questions): responseNumber = 0 def main(): print('Welcome, I am concerned about you and have a few questions. You can leave by saying "bye".') print("Something seems to be troubling you. How do you feel",end="") responses = [ "Interesting,Let's dive deeper.\nWhat other feelings come to mind when you think about feeling", "Really, how did you feel before you felt", "I wonder, do you think a lot about how you used to feel" ] interview(responses) # call the interview function using the responses defined above Cross out all of the comments. The computer ignores them. What symbol do these comments start with that sets them apart from the code that the computer needs to understand? these comments start with #

How many functions are in this program? # Eliza-like program def interview(questions): responseNumber = 0 # start with the first response userResponse = input( "? " ) # ask the person to type an answer while ( not "bye" in userResponse): print('\n\n' + questions[ responseNumber ] + " "+ userResponse ,end="") userResponse = input( "? " ) responseNumber+=1 if responseNumber==len(questions): responseNumber = 0 def main(): print('Welcome, I am concerned about you and have a few questions. You can leave by saying "bye".') print("Something seems to be troubling you. How do you feel",end="") responses = [ "Interesting,Let's dive deeper.\nWhat other feelings come to mind when you think about feeling", "Really, how did you feel before you felt", "I wonder, do you think a lot about how you used to feel" ] interview(responses) # call the interview function using the responses defined above Functions are parts of a program that has been divided up into sections. You define a function def is short for define How many functions are in this program? the main function is always used to start a program.

Underline the names of the functions # Eliza-like program def interview(questions): responseNumber = 0 # start with the first response userResponse = input( "? " ) # ask the person to type an answer while ( not "bye" in userResponse): print('\n\n' + questions[ responseNumber ] + " "+ userResponse ,end="") userResponse = input( "? " ) responseNumber+=1 if responseNumber==len(questions): responseNumber = 0 def main(): print('Welcome, I am concerned about you and have a few questions. You can leave by saying "bye".') print("Something seems to be troubling you. How do you feel",end="") responses = [ "Interesting,Let's dive deeper.\nWhat other feelings come to mind when you think about feeling", "Really, how did you feel before you felt", "I wonder, do you think a lot about how you used to feel" ] interview(responses) # call the interview function using the responses defined above Underline the names of the functions What does each function in this program do? The code that is part of a function is always indented. Draw boxes around the code in the functions the main function is always used to start a program.

# Eliza-like program def interview(questions): responseNumber = 0 # start with the first response userResponse = input( "? " ) # ask the person to type an answer while ( not "bye" in userResponse): print('\n\n' + questions[ responseNumber ] + " "+ userResponse ,end="") userResponse = input( "? " ) responseNumber+=1 if responseNumber==len(questions): responseNumber = 0 def main(): print('Welcome, I am concerned about you and have a few questions. You can leave by saying "bye".') print("Something seems to be troubling you. How do you feel",end="") responses = [ "Interesting,Let's dive deeper.\nWhat other feelings come to mind when you think about feeling", "Really, how did you feel before you felt", "I wonder, do you think a lot about how you used to feel" ] interview(responses) # call the interview function using the responses defined above Input statements wait for the human using the program to type in a response Where are the 2 places in the code where the computer will wait for a person to type in an answer?

Circle the input statements # Eliza-like program def interview(questions): responseNumber = 0 # start with the first response userResponse = input( "? " ) # ask the person to type an answer while ( not "bye" in userResponse): print('\n\n' + questions[ responseNumber ] + " "+ userResponse ,end="") userResponse = input( "? " ) responseNumber+=1 if responseNumber==len(questions): responseNumber = 0 def main(): print('Welcome, I am concerned about you and have a few questions. You can leave by saying "bye".') print("Something seems to be troubling you. How do you feel",end="") responses = [ "Interesting,Let's dive deeper.\nWhat other feelings come to mind when you think about feeling", "Really, how did you feel before you felt", "I wonder, do you think a lot about how you used to feel" ] interview(responses) # call the interview function using the responses defined above Circle the input statements

How many print statements are there? # Eliza-like program def interview(questions): responseNumber = 0 # start with the first response userResponse = input( "? " ) # ask the person to type an answer while ( not "bye" in userResponse): print('\n\n' + questions[ responseNumber ] + " "+ userResponse ,end="") userResponse = input( "? " ) responseNumber+=1 if responseNumber==len(questions): responseNumber = 0 def main(): print('Welcome, I am concerned about you and have a few questions. You can leave by saying "bye".') print("Something seems to be troubling you. How do you feel",end="") responses = [ "Interesting,Let's dive deeper.\nWhat other feelings come to mind when you think about feeling", "Really, how did you feel before you felt", "I wonder, do you think a lot about how you used to feel" ] interview(responses) # call the interview function using the responses defined above Output statements are messages from the computer to the person using the program. In a simple program they are messages that are printed to the screen. How many print statements are there?

Draw a zigzag line under each output statement # Eliza-like program def interview(questions): responseNumber = 0 # start with the first response userResponse = input( "? " ) # ask the person to type an answer while ( not "bye" in userResponse): print('\n\n' + questions[ responseNumber ] + " "+ userResponse ,end="") userResponse = input( "? " ) responseNumber+=1 if responseNumber==len(questions): responseNumber = 0 def main(): print('Welcome, I am concerned about you and have a few questions. You can leave by saying "bye".') print("Something seems to be troubling you. How do you feel",end="") responses = [ "Interesting,Let's dive deeper.\nWhat other feelings come to mind when you think about feeling", "Really, how did you feel before you felt", "I wonder, do you think a lot about how you used to feel" ] interview(responses) # call the interview function using the responses defined above Draw a zigzag line under each output statement

A loop is a part of the code that repeats # Eliza-like program def interview(questions): responseNumber = 0 # start with the first response userResponse = input( "? " ) # ask the person to type an answer while ( not "bye" in userResponse): print('\n\n' + questions[ responseNumber ] + " "+ userResponse ,end="") userResponse = input( "? " ) responseNumber+=1 if responseNumber==len(questions): responseNumber = 0 def main(): print('Welcome, I am concerned about you and have a few questions. You can leave by saying "bye".') print("Something seems to be troubling you. How do you feel",end="") responses = [ "Interesting,Let's dive deeper.\nWhat other feelings come to mind when you think about feeling", "Really, how did you feel before you felt", "I wonder, do you think a lot about how you used to feel" ] interview(responses) # call the interview function using the responses defined above A loop is a part of the code that repeats In this program, there is a loop that keeps repeating as long as the answer to the computer’s question is not “bye” Draw an arrow to show where the end of the loop goes back up to repeat

Draw an arrow to show where the end of the loop goes back up to repeat # Eliza-like program def interview(questions): responseNumber = 0 # start with the first response userResponse = input( "? " ) # ask the person to type an answer while ( not "bye" in userResponse): print('\n\n' + questions[ responseNumber ] + " "+ userResponse ,end="") userResponse = input( "? " ) responseNumber+=1 if responseNumber==len(questions): responseNumber = 0 def main(): print('Welcome, I am concerned about you and have a few questions. You can leave by saying "bye".') print("Something seems to be troubling you. How do you feel",end="") responses = [ "Interesting,Let's dive deeper.\nWhat other feelings come to mind when you think about feeling", "Really, how did you feel before you felt", "I wonder, do you think a lot about how you used to feel" ] interview(responses) # call the interview function using the responses defined above Draw an arrow to show where the end of the loop goes back up to repeat

Additional Resources "Is Eliza Human?" Use Python to build a chatbot. printing, user input, variables, if statements, while loops https://groklearning.com/csedweek/ CodingBat practice is Useful once functions have been taught http://codingbat.com/python Development environments for python Spyder Python Development Environment: http://code.google.com/p/spyderlib/ Python IdlePycharm Python Development Environment using Python 3.4.1Runestone: Interactive Python: http://interactivepython.org/runestone/static/CCPS_Python/index.html