Simple Functions and Names Sec 9-4 Web Design. Objectives The student will: Know how to create a simple function in Python. Know how to call a function.

Slides:



Advertisements
Similar presentations
Do I need a robot today? You only need a robot if your team has not shown me your octagon and/or the octagon in a function.
Advertisements

Functions Jay Summet. Aug Functions A function is a piece of code you can use over and over again Treat it like a black box You pass it (optional)
CS 1 with Robots Functions Institute for Personal Robots in Education (IPRE)‏
Introduction to Python
Chapter 2 Writing Simple Programs
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Main task -write me a program
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
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.
How to turn on the robot How to start Bluetooth How to connect to robot How to initialize the robot How to not break the robot Sec Getting Started.
Simple Python Loops Sec 9-7 Web Design.
CH1 – A 1 st Program Using C#. Program Set of instructions which tell a computer what to do. Machine Language Basic language computers use to control.
Guide to Programming with Python Chapter Two Basic data types, Variables, and Simple I/O: The Useless Trivia Program.
Introduction to Python
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
First Program  Open a file  In Shell  Type into the file: 3  You did it!!! You wrote your first instruction, or code, in python!
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Functions.
Computer Science 101 Introduction to Programming.
Python Functions.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
FUNCTIONS. Topics Introduction to Functions Defining and Calling a Void Function Designing a Program to Use Functions Local Variables Passing Arguments.
Python Let’s get started!.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
1- How to connect the robot to the pc Sec Getting Started 3- How to move the robot Sec Scribbler movements 4- How to make a turn 11- How to.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Creating and Using Modules Sec 9-6 Web Design. Objectives The student will: Know how to create and save a module in Python Know how to include your modules.
Shell Scripting September 27, 2004 Class Meeting 6, Part II * Notes adapted by Lenwood Heath from previous work by other members of the CS faculty at Virginia.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
Introducing Python 3 Introduction to Python. Introduction to Python L1 Introducing Python 3 Learning Objectives Know what Python is and some of the applications.
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.
Next Week… Quiz 2 next week: –All Python –Up to this Friday’s lecture: Expressions Console I/O Conditionals while Loops Assignment 2 (due Feb. 12) topics:
Lecture III Syntax ● Statements ● Output ● Variables ● Conditions ● Loops ● List Comprehension ● Function Calls ● Modules.
Chapter 2 Writing Simple Programs
C++ First Steps.
Introducing Python Introduction to Python.
Writing algorithms Introduction to Python.
Topic: Python’s building blocks -> Variables, Values, and Types
Topics Introduction to Functions Defining and Calling a Void Function
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Python Let’s get started!.
Introduction to Python
Introduction to Python
Functions Jay Summet.
Topic: Python’s building blocks -> Variables, Values, and Types
Topic: Functions – Part 2
Statement atoms The 'atomic' components of a statement are: delimiters (indents, semicolons, etc.); keywords (built into the language); identifiers (names.
Functions CIS 40 – Introduction to Programming in Python
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
First Python Program Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An.
Fundamentals of visual basic
Topics Introduction to Functions Defining and Calling a Void Function
Functions Institute for Personal Robots in Education (IPRE)‏
Functions Jay Summet.
Topics Introduction to Functions Defining and Calling a Function
15-110: Principles of Computing
CISC101 Reminders All assignments are now posted.
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
Functions Institute for Personal Robots in Education (IPRE)‏
12th Computer Science – Unit 5
Functions Institute for Personal Robots in Education (IPRE)‏
Functions Jay Summet.
Introduction to Computer Science
Variables in C Topics Naming Variables Declaring Variables
Functions Taken from notes by Dr. Neil Moore & Dr. Debby Keen
Functions Jay Summet.
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Simple Functions and Names Sec 9-4 Web Design

Objectives The student will: Know how to create a simple function in Python. Know how to call a function in Python. Know the rules for “names” in Python

Functions A function is a piece of code you can use over and over again – Treat it like a black box You pass it (optional) values, it does some work, and it (optionally) returns values You “call it”,”invoke it”, or “use it” by using its name and parentheses The things you pass it go inside the parentheses – output = function( input ) function input output

Functions As in any programming language Python has functions. – Functions allows you to modularize your code Easier to read Easier to debug Easy to use over and over

Functions The basic syntax for defining a Python function takes the form: def ( ):...

Functions def ( ):... Note that the lines of the function are indented. – The number of spaces that make up the indentation is not that important as long as they are all the same.

Improper Functions This will not be accepted by Python: Red bar shows the point of the error This is acceptable

Python Functions in IDLE IDLE will automatically indent lines in a function. – To end the function simple un-indent the line. IDLE also uses colors to help the readability of a program: Red – Comments Blue – Function Names Orange – Python word

Calling (Invoking) a Function To call a function you type the function: yoyo() forward()

Rules for Python Names Some names are reserved by the system and are already defined. Examples are things like: def, print, if, else, while, for, in, and, or, not, return. These names are built in keywords. A name in Python must begin with either an alphabetic letter (a-z or A-Z) or the underscore (i.e. _) and can be followed by any sequence of letters, digits, or underscore letters. For example, Vaild:Invalid: iRobot2robots myRobotRobots-r-cool jitterBug jitterBug2 my2cents my_2_cents

Summary Functions are defined by: def ( ):... Functions are called by FUNCTION() Function names must begin with either an alphabetic letter (a-z or A-Z) or the underscore (i.e. _) and can be followed by any sequence of letters, digits, or underscore letters.

Rest of Today Take the code for the octagon and put it in a function. Call the function 4 times. When the function is done show me the results.