Learning to Program in Python

Slides:



Advertisements
Similar presentations
1 Software Engineering Lecture 11 Software Testing.
Advertisements

Coaching for School Improvement: A Guide for Coaches and Their Supervisors An Overview and Brief Tour Karen Laba Indistar® Summit September 2, 2010.
Fundamentals of Python: From First Programs Through Data Structures
Lecture 15 Practice & exploration Subfunctions: Functions within functions “Guessing Game”: A hands-on exercise in evolutionary design © 2007 Daniel Valentine.
Fundamentals of Python: First Programs
1 Shawlands Academy Higher Computing Software Development Unit.
LESSON 8 Booklet Sections: 12 & 13 Systems Analysis.
The Software Development Process
MA471 Fall 2003 Lecture 2. On With The Games Today we are going to watch each group play a couple of rounds of cards. We will go through the game slowly.
Coding Time This is a starter activity and should take about 10 minutes [ slide 1 ] 1.Log in to your computer 2.Open IDLE 3.Start a script session (Select.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
Functions Part I (Syntax). What is a function? A function is a set of statements which is split off into a separate entity that can be used like a “new.
L5 Computing Team Project Final Presentation Guidelines.
GCSE COMPUTER SCIENCE Practical Programming using Python
Year 2 Stay and Play!.
Component 1.6.
Fundamentals of Python: First Programs
3.1 Fundamentals of algorithms
Topic: Recursion – Part 2
Annual Performance Management Cycle Management Training Tutorial
Use Case Model.
IF statements.
Topic: Functions – Part 2
Software engineering – 1
Functions CIS 40 – Introduction to Programming in Python
Functions.
Computer Networks Lesson 3.
Learning to Program in Python
Learning to Program in Python
Learning to Program in Python
Print slides for students reference
Writing Functions( ) (Part 5)
Learning to Program in Python
Learning to Program in Python
Learning to Program in Python
Computer Science and an introduction to Pascal
Learning to Program in Python
Learning to Program in Python
Learning to Program in Python
Learning to Program in Python
Learning to Program in Python
Learning to Program in Python
Learning to Program in Python
More Loops.
Learning to Program in Python
Programming In Lesson 3.
Learning to Program in Python
Lesson Objectives Aims You should be able to:
Learning to Program in Python
Unit 6: Application Development
Software Requirements Specification Document
Mapwork Lesson 2 Where am I?
Coding Concepts (Standards and Testing)
Writing Functions( ) (Part 4)
Learning to Program in Python
Topics Introduction to Functions Defining and Calling a Void Function
Concurrency: Mutual Exclusion and Process Synchronization
Chapter 11 Describing Process Specifications and Structured Decisions
PYTHON: BUILDING BLOCKS Sequencing & Selection
Topics Introduction to Functions Defining and Calling a Function
Bulloch Information Session
Computer Networks Lesson 3.
Python SAT 1 Feedback.
 A function is a named sequence of statement(s) that performs a computation. It contains  line of code(s) that are executed sequentially from top.
CMPT 120 Lecture 19 – Unit 3 – Graphics and Animation
Lecture 20 – Practice Exercises 4
Lecture 20 – Practice Exercises 4
Section B: Scripted Piece. The Crucible
Functions and Abstraction
Presentation transcript:

Learning to Program in Python Concept 8 UNIT Testing (using definitions) Ensure the teams of students can easily transfer files (email, shared learning space) within the group.

Learning Intentions From this lesson the students will be able to: Develop functions to perform specific tasks and test each function. Import tested functions into a main program. Verify the main program works correctly. A key line of Python to include at the end of each program in which functions are to be imported is : if __name__ = “__main__” : myFn() The function that is called (in this case myFn() ) is the main function that will execute the task. Keep this until the tasks are complete. So the students can enhance the import process.

recall from FUNCTIONS We can pass in as many parameters to a function as we like: def fancyNumberOfInputs(a, b, c, x, y, z) : BUT we can only ever have one (if any) return from a function. A brief overview of how to define a definition.

Remember a STRING is a LIST CHALLENGE REVISITED TEAMS of 3 Write 3 definitions to do the following : Take a word (string) from the user. Check if the word is a Palindrome Allow the user to check as many strings as they wish until they decide to quit. This task was done individually in the section on functions (both recursively and non-recursively) . Recall that a cool way to reverse a list is revPhrase = userPhrase[ : : -1] …… let the students figure out their own ways first. A sample version of what the modular design could look like is in a folder in this section of the ncca.ie website. RACECAR Remember a STRING is a LIST

CHALLENGE REVISITED TEAMS of 3 Rules & Roles .. There must be at least 3 separate functions written by the 3 separate members of the team. Each function must be a standalone function and must be tested with some inputs ensuring they give the expected outputs. There must a main parent program which calls the other functions and controls the main interface with the user. Key Aim: Students do unit tests to ensure their part of the jigsaw works (with help from the team if necessary) without being told it is UNIT testing LO 2.19 students should be able to test solutions and decisions to determine their short-term and long-term outcomes

What are the pros and cons? CHALLENGE REFLECTION TEAMS of 3 Rules & Roles .. REFLECT on the task and the role of testing each individual function. Why Test this way? What are the pros and cons? How would students describe this process known as UNIT TESTING. See http://computationaltales.blogspot.ie/2011/05/importance-of-unit-testing-magical.html ….. Or just Google some the key words. See online resources on NCCA/PDST for descriptions of other tests such as system/integration tests or function (black box) tests. The 4 stages are UNIT(1 block) -> FUNCTION(block interfaces) -> SYSTEM(all blocks) ->ACCEPTANCE(user) testing. LO 2.22 students should be able to explain the different stages in software testing

setting up IMPORT #last line of Program1 needs to be : Program1 … let’s say the function is called : returnUserPhrase() #last line of Program1 needs to be : if __name__ == “__main__”: returnUserPhrase() Once the tasks are coming together, show the students how to import their functions into the main program. A sample of the code is given in the folder in the section for this concept on the ncca.ie website. …. Some of the teams could be encouraged into doing this themselves before being shown.

setting up IMPORT #last line of Program2 needs to be : Program2 … let’s say the function is called : checkIfPalindrome(userPhrase) #last line of Program2 needs to be : if __name__ == “__main__”: checkIfPalindrome() Once the tasks are coming together, show the students how to import their functions into the main program … A sample of the code is given …. Some of the teams could be encouraged into doing this themselves before being shown.

setting up IMPORT #first lines: Main Program … from Program1 import returnUserPhrase from Program2 import checkIfPalindrome Once the tasks are coming together, show the students how to import their functions into the main program … A sample of the code is given …. Some of the teams could be encouraged into doing this themselves before being shown. The functions can now be used within the main program as if they were contained and written within the program. LO 2.3 students should be able to implement modular design to develop hardware or software modules that perform a specific function

NEXT TEAM CHALLENGE TEAMS of 3 Write 3 functions to create the following GUESSING number game. Ask the user for a number between 1 and some number, and verifies an integer has been entered. Generate a random number (from random import randint) and invites the user to guess the number. Inform the user if their guess if too high or too low or correct. Allow the user to quit the game or continue for another round. Keep some statistics on their mean number of guesses or time taken to play the game or some other stat. This task may have been done before individually or in groups. Encourage a modular approach, ensuring that the child programs (the first 2 in the slide above) are unit tested before being used by the parent program (the 3rd program in the slide above)

CHALLENGE REVISITED TEAMS of 3 Rules & Roles .. Change the person in charge of the main program from the last challenge There must be at least 3 separate functions written by the 3 separate members of the team. Each function must be a standalone function and must be UNIT tested with some inputs giving the expected outputs. There must a main parent program which calls the other functions and controls the main interface with the user. Key Aim: Students do unit tests to ensure their part of the jigsaw works (with help from the team if necessary) without being told it is UNIT testing LO 1.23 students should be able reflect and communicate on the design and development process

Lesson Review As a result of these tasks: I can develop individual functions to perform specific tasks and test each function. I can import tested functions into a main program. I can describe UNIT testing, with specific examples of how and why it is done The LOs indicated are ones that can be achieved through these tasks and lesson. It is neither an exhaustive or exclusive list. Please refer to the SPEC on the ncca.ie website.