Week 4 : Function with parameters and return values.

Slides:



Advertisements
Similar presentations
CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Advertisements

Decision Making Using Excel
Iteration in C H&K Chapter 5 Instructor – Gokcen Cilingir Cpt S 121 (July 1, 2011) Washington State University.
Basic Elements of C++ Chapter 2.
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.
Middle School Grades 6-8 Creating Calendars in Publisher.
Functions.
Agenda Review Compiling Review Data Types Integer Division Composition C++ Mathematical Functions User Input Reading: , 8.11 Homework #3.
Computer Science 1000 Spreadsheets II Permission to redistribute these slides is strictly prohibited without permission.
Line Continuation, Output Formatting, and Decision Structures CS303E: Elements of Computers and Programming.
The if statement and files. The if statement Do a code block only when something is True if test: print "The expression is true"
Introduction to Python
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
THE BIG PICTURE. How does JavaScript interact with the browser?
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
Sorting and Modules. Sorting Lists have a sort method >>> L1 = ["this", "is", "a", "list", "of", "words"] >>> print L1 ['this', 'is', 'a', 'list', 'of',
Functions and subroutines – Computer and Programming.
Data Types Integer 15 StringHelloThere! Float/Real BooleanYes / No CharP.
Textbook Problem Java – An Introduction to Problem Solving & Programming, Walter Savitch, pp.219, Problem 08.
Working on exercises (a few notes first). Comments Sometimes you want to make a comment in the Python code, to remind you what’s going on. Python ignores.
Xin Liu Feb 11, * Part 1 1. What value does s have, after this code is run? s = '*' s = s + s s = s + s + s (A) '**' (B) '***' (C) '****' (D) '*****'
Python Programming Using Variables and input. Objectives We’re learning to build functions and to use inputs and outputs. Outcomes Build a function Use.
CSI 1390: Introduction to Computers TA: Tapu Kumar Ghose Office: STE 5014 Office hours: Thursday 1300 – 1400hrs.
Q and A for Sections 2.9, 4.1 Victor Norman CS106 Fall 2015.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Lesson Topic: True and False Number Sentences Lesson Objective: I can…  Explain what the equality and inequality symbols include. They will determine.
Functions. Built-in functions You’ve used several functions already >>> len("ATGGTCA")‏ 7 >>> abs(-6)‏ 6 >>> float("3.1415")‏ >>>
Week 3 : Last step with Hubo, Python objects
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Math – What is a Function? 1. 2 input output function.
CS 330 Programming Languages 10 / 02 / 2007 Instructor: Michael Eckmann.
Week 6 : Sequences ( lists, strings, and tuples ).
Working on exercises (a few notes first)‏. Comments Sometimes you want to make a comment in the Python code, to remind you what’s going on. Python ignores.
Math, Data Types. Python Math Operations OperationOperator Addition + Subtraction – Multiplication * Division (floating point) / Division (integer) //
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.
Triangle Inequalities. Definitions Theorem 5-12 Triangle inequality Theorem- Sum of the lengths of any two sides of a triangle is greater than the length.
Lesson 5.4 The Triangle Inequality. Triangle Inequality Theorem The sum of the lengths of any two sides of a triangle is greater than the length of the.
Week 9 : Text processing (Reading and writing files)
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
More Sequences. Review: String Sequences  Strings are sequences of characters so we can: Use an index to refer to an individual character: Use slices.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
5.4 The Triangle Inequality What you’ll learn: 1.To apply the triangle inequality Theorem 2.To determine the shortest distance between a point and a line.
Week 7 : String and photo processing. Today’s Tasks  Practice list and string  Convert Decimal to any radix base number  Between Binary and Hexadecimal.
Functions CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Indentations makes the scope/block Function definition def print_message (): print “hello” Function usages print_message () hubo.move ()// hubo is a class.
CSC 1010 Programming for All Lecture 5 Functions Some material based on material from Marty Stepp, Instructor, University of Washington.
Input, Output and Variables GCSE Computer Science – Python.
ENGINEERING 1D04 Tutorial 2. What we’re doing today More on Strings String input Strings as lists String indexing Slice Concatenation and Repetition len()
Chapter Topics The Basics of a C++ Program Data Types
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
Basic Elements of C++.
Basic Elements of C++ Chapter 2.
Notes Over 2.1 Function {- 3, - 1, 1, 2 } { 0, 2, 5 }
Python I/O.
exa.im/stempy16.files - Session 12 Python Camp
Suppose I want to add all the even integers from 1 to 100 (inclusive)
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Functions continued.
The Triangle Inequality
Introduction to Python
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
Data Types and Maths Programming Guides.
Python 10 Mr. Husch.
Hint idea 2 Split into shorter tasks like this.
Programming Concepts and Database
Using Modules.
Presentation transcript:

Week 4 : Function with parameters and return values

Today’s Topic  Variables  Interacting with a user’s input (function ‘raw_input’)  Function with parameters and return values

Practices  Teach Hubo How to Add  Addition  Being Mathematician  being Euclid  being Edmund Gunter (#1)  being Gunter Reloaded (#2)  being Gunter Reloaded (#3)  Caution: Save your python files in C:/cs101/ and clear the directory when you complete the tasks.

Task | Variables – Addition Teach Hubo how to add two numbers There are two numbers in base 10 on the row 1 and 2 Add two numbers and put the result on the row 1 ※ Your program must work for add1.wld, add2.wld, and add34.wld ※ Hint : Use variables in order to remember two numbers add34.wld Before After add1.wld add2.wld

Task | being Euclid  Given three numbers a, b, and c, it is possible to form a triangle whose sides have length a, b, and c if and only if the triangle inequality holds. That is, every side must be shorter than the sum of the other two sides.

Task | being Euclid (cont’d)  Define a function ‘is_triangle()’ which  takes three float values (three parameters)  returns True or False depending on whether three values can form a triangle  Write a program which 1.asks the user to enter three float values 2.evaluates input numbers using function ‘is_triangle()’ 3.outputs YES or NO depending on the result of ‘is_triangle()’ function ※ Hint: You must call the function ‘raw_input’ and use ‘print’ outside of the function.  Sample input and output Side a: 2.3 Side b: 4.3 Side c: 5.6 YES

Task | being Edmund Gunter  Modify the following program to ask the user for the number of steps (instead of using 41 fixed steps). import math sin = math.sin pi = math.pi for i in range(41): x = float(i) / 40.0 * 2 * pi print sin(x) for i in range(3) print i Hint : Try this to find out. Note : By the way, why 41 in range?

Task | being Gunter Reloaded #2  Change the program to print a nice curve like this: 40 80

 Change the program to print a curve like this instead: Hint : Convert the result of ‘sin’ function to a number of blank and a single asterisk (e.g.) print “ “ * 5 + “!!” !! Task | being Gunter Reloaded #3 5

Any Questions?