Useful IDLE Alt-ENTER Commenting-out. Writing a Program CMSC 120: Visualizing Information 2/14/08.

Slides:



Advertisements
Similar presentations
08/2012Tanya Mishra1 EASYC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817.
Advertisements

Programming TBE 540 Farah Fisher. Objectives After viewing this presentation, the learner will be able to… Given a task, create pseudocode Given pseudocode,
ITEC113 Algorithms and Programming Techniques
Scripts and Flow Control. Scripts So far we have been entering commands directly into the command line But there is a better way Script files (and functions)
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
Functions MATLAB’s power comes from functions Functions allow projects to be partitioned into manageable, testable, reusable modules.
1 Modularity In “C”. 2 What is Modularity?  Modularity, is the heart of the high level, structured languages.  Means breaking down a big problem into.
Program Design and Development
Algorithms. Introduction Before writing a program: –Have a thorough understanding of the problem –Carefully plan an approach for solving it While writing.
Chapter 1 Program Design
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
Topic 4 – Programmer- Defined Functions. CISC 105 – Topic 4 Functions So far, we have only seen programs with one function, main. These programs begin.
Prof. R. Willingale Department of Physics and Astronomy 2nd Year C+R 2 nd Year C and R Workshop Part of module PA2930 – 2.5 credits Venue: Computer terminal.
Python quick start guide
Genetic Programming.
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 02.
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
Chapter 2: Developing a Program Prelude to Programming Concepts and Design Copyright © 2001 Scott/Jones, Inc.. All rights reserved. 1 Chapter 2 Developing.
INTRODUCTION TO PROGRAMMING STRUCTURE Chapter 4 1.
Simple Program Design Third Edition A Step-by-Step Approach
Introduction to Python
Algorithmic Problem Solving CMSC 201 Adapted from slides by Marie desJardins (Spring 2015 Prof Chang version)
Programming. What is a Program ? Sets of instructions that get the computer to do something Instructions are translated, eventually, to machine language.
Invitation to Computer Science, Java Version, Second Edition.
INTRODUCTION TO ALGORITHMS PROGRAMMING. Objectives Give a definition of the term algorithm Describe the various parts of the pseudocode algorithm or algorithm.
Introduction to Computational Linguistics Programming I.
Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
Introduction. 2COMPSCI Computer Science Fundamentals.
TMF1013 : Introduction To Computing Lecture 1 : Fundamental of Computer ComputerFoudamentals.
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
Introduction to Computer Programming Using C Session 23 - Review.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.
IXA 1234 : C++ PROGRAMMING CHAPTER 1. PROGRAMMING LANGUAGE Programming language is a computer program that can solve certain problem / task Keyword: Computer.
ORDER OF CONTENT AND INSTRUCTIONS A program in its simplest form usually contains three kinds of activity:  INPUT : The program asks the user for some.
How to Read Code Benfeard Williams 6/11/2015 Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors.
The Programming Process Define the problem* Make or buy software? Design the program * Code (write) the program Test (debug) the program Document the.
COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving  Recognizing Patterns  If you can find a pattern in the way you solve.
CS221 Algorithm Basics. What is an algorithm? An algorithm is a list of instructions that transform input information into a desired output. Each instruction.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
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.
How Are Computers Programmed? CPS120: Introduction to Computer Science Lecture 5.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Sequences CMSC 120: Visualizing Information 2/26/08.
Controlling Program Flow with Decision Structures.
1 UMBC CMSC 104, Section Fall 2002 Functions, Part 1 of 3 Topics Top-down Design The Function Concept Using Predefined Functions Programmer-Defined.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Getting Started With Python Brendan Routledge
CSE 110: Programming Language I Matin Saad Abdullah UB 404.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Software Engineering Algorithms, Compilers, & Lifecycle.
Introduction to Programming
1-1 Logic and Syntax A computer program is a solution to a problem.
Programming Mehdi Bukhari.
11/10/2018.
IDLE Hints To re-load a module after making changes:
Programming Right from the Start with Visual Basic .NET 1/e
Programming Funamental slides
Computational Thinking for KS3
CS285 Introduction - Visual Basic
The Programming Process
Introduction to Computer Science
General Computer Science for Engineers CISC 106 Lecture 03
Presentation transcript:

Useful IDLE Alt-ENTER Commenting-out

Writing a Program CMSC 120: Visualizing Information 2/14/08

The Inner Workings: A Review

Statements Executable code A program is a sequence of one or more statements Do not produce values Executed for their side effects Simple Statements ◦ Assignment: x = 5 ◦ Return: return x ◦ Import: from pylab import * ◦ Print: print x

Expressions When executed, evaluates to a value Usually have no side effects Order of operations: >>> x = 5*2+7/8-(3+mean(y))**7 ◦ Start at innermost pair of parentheses and work your way out Evaluate functions to obtain their value ◦ ** ◦ *, /, % ◦ +, -

Values Data Types: ◦ A classification that tells the computer what kind of data is being used ◦ Limits potential values ◦ Limits potential operation ◦ Determines precision and Accuracy ◦ int, long int, float, string, boolean

Objects Dynamic data type ◦ Knows stuff ◦ Does stuff ◦ A set of related data ◦ Operations (methods) needed to access and manipulate that data

Variables Names assigned to values Store Identify Manipulate Transfer ◦ Parameters

Blocks of Code Functions ◦ A set of commands that work together to complete a task ◦ Reuseable ◦ Flexible ◦ Define ◦ Invoke Modules ◦ import

Programs Any set of instructions to the computer Self-executing set of instructions to the computer

# File: plotDrugData.py # Purpose: A useful function # Author: Emily Allen # import supporting files from pylab import * from DrugData import * # define the function def plotDrugData(data, name): plot(Year, data, ' -rs') xlabel('Year') ylabel('Percentage') title(name + ' Drug Use ') show() >>> from plotDrugData import * >>> plotDrugData(Marijuana, ' Marijuana ' ) >>> from plotDrugData import * >>> plotDrugData(Marijuana, ' Marijuana ' ) Define Invoke

# File: plotDrugData.py # Purpose: A useful function # Author: Emily Allen # import supporting files from pylab import * from DrugData import * # define the function def plotDrugData(data, name): plot(Year, data, ' -rs') xlabel('Year') ylabel('Percentage') title(name + ' Drug Use ') show() def main(): plotDrugData(Marijuana, 'Marijuana') main()

Programs Any set of instructions to the computer Self-executing set of instructions to the computer def main(): do something : do something main()

THE ART OF PROBLEM SOLVING Algorithm Design

A Problem You have been provided with a record of numbers of life births by method of delivery and age of the mother for the state of California in Write a program that calculates the percentage of total live births by a method and plots the result versus Mother’s Age in a bar chart. The plot should be labeled and titled appropriately.

Top-Down Design Define the problem Express the solution in terms of smaller problems. Now, break down the smaller problems into smaller problems. Repeat until they are trivial

Defining the Problem 1. What is the task? 2. What information is required? 3. Is any of that information missing? 4. Any inputs? Any outputs? 5. What are the characteristics of the system? Its elements? What is the job? NOT how to do the job.

Develop an Algorithm 1. What big steps do I need to take to accomplish the task? 2. How can I break those big steps down into easily solvable small steps? 3. How can I generate what I am missing from what I have? Algorithm: set of sequential instructions that are followed to solve a problem Pseudocode: expression of an algorithm in everyday language

A Problem You have been provided with a record of numbers of life births by method of delivery and age of the mother for the state of California in Write a program that calculates the percentage of total live births by a method and plots the result versus Mother’s Age in a bar chart. The plot should be labeled and titled appropriately.

Defining the Problem 1. What is the task?  To calculate and visualize the % of live births per a given method versus Mother’s Age 2. What information is required?  Percentage of births by a given method 3. Is any of that information missing?  Percentage of births by a given method 4. Any inputs? Any outputs?  Method type  The Visualization

Develop an Algorithm 1. What big steps do I need to take to accomplish the task?  Set Method  Calculate Percentage  Plot the Percentage 2. How can I break those big steps down into easily solvable small steps?  Plot the Percentage  Generate plot  Label plot  Show plot 3. How can I generate what I am missing from what I have?  Percentage = method / total

Pseudocode Set method Calculate the percentage ◦ Percentage = method / total Generate Plot ◦ plot Mother’s Age versus Percentage ◦ xlabel is Mother’s Age ◦ ylabel is Percentage ◦ title is the method ◦ show the plot

Bottom-Up Implementation One task usually = one function Pick a task and write it, evaluate it, debug it, until it works ◦ e.g., Calculate the percentage When satisfied, begin the next task from LiveBirthData import * from percent import * # function for calculating percent of total def calcPercentage(method): return percent(method, Total) from LiveBirthData import * from percent import * # function for calculating percent of total def calcPercentage(method): return percent(method, Total)

from LiveBirthData import * from percent import * from pylab import * # function for calculating percent of total def calcPercentage(method): return percent(method, Total) # function for plotting def plotPercentage(percentage, label): bar(MotherAge, percentage) xlabel('Age of Mother') ylabel('Percent Total Live Births') title = (label) show() from LiveBirthData import * from percent import * from pylab import * # function for calculating percent of total def calcPercentage(method): return percent(method, Total) # function for plotting def plotPercentage(percentage, label): bar(MotherAge, percentage) xlabel('Age of Mother') ylabel('Percent Total Live Births') title = (label) show() Once all tasks are completed, assemble the whole algorithm into a program

# main program def main(): method = Cesarean # choose the method label = 'Cesarean' # set label # calculate the percentage percentage = calcPercentage(method) # plot the percentage plotPercentage(percentage, label) main() # run the program # main program def main(): method = Cesarean # choose the method label = 'Cesarean' # set label # calculate the percentage percentage = calcPercentage(method) # plot the percentage plotPercentage(percentage, label) main() # run the program 1. What big steps do I need to take to accomplish the task?  Set Method  Calculate Percentage  Plot the Percentage