Compsci 6/101, Spring 2012 3.1 More on Python, Tools, Compsci 101 l APTs, Assignments, Tools  APT: Algorithmic Problem-solving and Testing  How to get.

Slides:



Advertisements
Similar presentations
compilers and interpreters
Advertisements

I210 review Fall 2011, IUB. Python is High-level programming –High-level versus machine language Interpreted Language –Interpreted versus compiled 2.
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
1 Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
Reasons to study concepts of PL
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.
Introduction to High-Level Language Programming
1 CSC 221: Introduction to Programming Fall 2012 course overview  What did you set out to learn?  What did you actually learn?  Where do you go from.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Abstraction IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 17, 2013 Carolyn Seaman University of Maryland, Baltimore County.
Introduction to Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg.
CIS Computer Programming Logic
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Compsci 101, Fall Plan for the week: Week 2, Sept 1-5 l Understanding program structure  Defining, testing, calling functions  How to run a.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
Compsci 06/101, Fall Compsci 6/101: Sept 6-10 l We've looked at the language Python  Names and types: int, float, long, String, file, …  Operations:
Compsci 101.2, Fall PFTT (plan for this Thursday) l What is a Python program?  In the context of what we do in Compsci 101  In a neuroscience.
Abstraction IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 17, 2013 Marie desJardins University of Maryland, Baltimore County.
Compsci 06/101, Fall What will we do today? l Practice solving problems  Solving problems without a computer  Is this different than solving.
JAVA BASICS: Variables and References SYNTAX, ERRORS, AND DEBUGGING.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Compsci 101.2, Fall Plan For the Week l Solve problems by programming in Python  Like to do "real-world" problems, but we're very new to the.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
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.
Compsci 06/101, Fall What will you do in Compsci 6 Today? l Learn about selection and if/else statements  In context of solving problems  Understanding.
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.
Functions. Built-in functions You’ve used several functions already >>> len("ATGGTCA")‏ 7 >>> abs(-6)‏ 6 >>> float("3.1415")‏ >>>
Compsci 6/101, Spring PFTW: Sequences aka Strings&Lists l From Return values to Random-ness [aka two R's]  What power does random provide? 
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
CompSci 6 Programming Design and Analysis January 17, 2006 Prof. Rodger.
Compsci 101.2, Fall PFTWeek l Introduce new Python concepts  Control: if, elif, else, for  Data: Strings, Lists Operators on data: slicing,
I Power Higher Computing Software Development High Level Language Constructs.
Compsci 06/101, Fall Vocabulary l What's the Spanish word for 'boy'? 'eat'?  How do you know? l What about the Turkish equivalents?  How do.
Python Functions : chapter 3
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.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
Georgia Institute of Technology Speed part 4 Barb Ericson Georgia Institute of Technology May 2006.
Compsci 101, Fall Plan For The Day (PFTD) l Practice solving problems  Some solved with a computer, some with Python  Differences in solving.
CS 177 Week 10 Recitation Slides 1 1 Debugging. Announcements 2 2.
Compsci 6/101, Spring PFTW: Functions, Control, Python/Tools l How do functions work and why do we use them?  Functions we call (APIs), Functions.
Compsci 06/101, Spring Compsci 6: PFTW l Problem solving and (Python) programming  What are the steps in solving an APT?  How do you get better.
CompSci 101 Introduction to Computer Science January 26, 2016 Prof. Rodger compsci 101, spring
Skill Area 311 Part B. Lecture Overview Assembly Code Assembler Format of Assembly Code Advantages Assembly Code Disadvantages Assembly Code High-Level.
CSCI 161 Lecture 3 Martin van Bommel. Operating System Program that acts as interface to other software and the underlying hardware Operating System Utilities.
Chapter 1: Introduction to Computers and Programming.
Software Engineering Algorithms, Compilers, & Lifecycle.
Terms: Software  Set of instructions  aka programs  Operating System:  Special software whose job it is to translateinstructions into hardware instructions.
Basic Concepts: computer, program, programming …
Introduction to Programming
Introduction to Algorithms
Introduction to Programming
Introduction to programming
CSCI-235 Micro-Computer Applications
CompSci 101 Introduction to Computer Science
Topic: Python’s building blocks -> Variables, Values, and Types
Text by: Lambert and Osborne
Compsci 6/101: PFTW What is Python? What is a programming language?
Introduction to Programming
Assembler, Compiler, Interpreter
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Introduction to Programming
Assembler, Compiler, Interpreter
Introduction to Algorithms
Introduction to Programming
Class code for pythonroom.com cchsp2cs
Dasar-Dasar Pemrograman 2: Java Basics
Functions, Procedures, and Abstraction
Presentation transcript:

Compsci 6/101, Spring More on Python, Tools, Compsci 101 l APTs, Assignments, Tools  APT: Algorithmic Problem-solving and Testing  How to get help and when to get it l Types, values, and operations on them  Names and types: int, float, string, file, list, long, …  Operations: *, +, -, /, %, **  Functions and methods on types: string, list, files l Functions: organizing code (and ideas)  Functions, modules, indentation, naming  Parameterization to generalize solutions  Return values to caller of function

Compsci 6/101, Spring Functions: abstractions over code l Naming something gives you power  How do you read a file into a string?  What is length of a string? Of a list? l We can write and call functions  Re-use and/or modify  Store in module, import and re-use functions  Import standard modules and use functions from them l Functions can (should?) return a value  We've seen len return an int, what about file.read()?  Other functions return Strings, floats, or other types

Compsci 6/101, Spring Re-use: Counting words in file def wordCount(filename): file = open(filename) all = file.read() words = all.split() return len(words) if __name__ == "__main__": name = "/data/romeo.txt" print "# words in",name, print "=",wordCount(filename)

Compsci 6/101, Spring Running Python Program/Module l Python is an interpreter, platform specific  So is Java, so is Android, … contrast compilers  Python can execute a.py file, need a "launch point" l Convention in Python and other languages  Start with section labeled __main__, that's run if __name__ == "__main__": statements here Statements here l Boilerplate, don't memorize

Compsci 6/101, Spring Anatomy of a Python function def name(params): body l Define a function, provide a name, provide parameters, provide a function body  How to decide on name?  Do we need parameters?  What does body of function do l Functions provide a named abstraction over code  Huh? What is math.factorial(15) "hello".upper()

Compsci 6/101, Spring Revisiting functions l Python Heron’s formula or BMI (Body Mass Index)  What’s the name of the function  What are parameters that enable function use/call l How do we write and test APTs  What’s the name of the function  What are parameters that enable function use/call  Who writes the function? Who calls the function? l How will you decide on these things in writing your own code?

Compsci 6/101, Spring Design, Implementation, Testing l Designing Python code and functions  What do you want the code to do?  Other aspects of code, e.g., portability, efficiency, size, …  Understand how to solve a problem without computer l Implementing design in code  Translation of ideas into vocabulary of Python  We don't have a large vocabulary, but it will grow! l Testing code, functions  How do you know when function is right?  What confidence can testing provide?  APT testing is similar to Unit Testing (well known)

Compsci 6/101, Spring Nancy Leveson: Software Safety l Mathematical and engineering aspects, invented the discipline  Air traffic control  Microsoft word “ There will always be another software bug; never trust human life solely on software” huffington post?huffington post? l Therac 25: Radiation machine   l Software and steam engines Software and steam engines

Compsci 6/101, Spring Running Python l Can run in Eclipse Console Window  How to start? What to type?  Also run on command-line, e.g. simple Mac/Linux l Can import code into another module/.py file  See APT examples and how to run them  Understand how your Python code is executed  Understand where Python code is and how it got there l How do we test your code to grade it, evaluate it?  APTs: auto-test, other assignments, human-in-the-loop

Compsci 6/101, Spring Language and Problems in Context l Convert Spanish Wikipedia page to English  How do we convert HTML to text? l How do you determine if 2040 is a leap year?  Any specified year is a leap year? l How do we make an image larger, more red, …  What is an image? How do read it? Convert it? Access it? l How do we find the BMI for everyone  What's the right tool for this? Why use Python? Why not?

Compsci 6/101, Spring Looping in Python l What is a string?  Sequence of characters that supports some operations l What is a list?  Sequence of elements that supports some operations l What is a (text) file?  Sequence of lines that supports some operations l Elements of the sequence are indexed  What is an index, where does indexing begin? Zero!  Value of s[a], s[a:b], s[a:] compare s[:b]

Compsci 6/101, Spring How do we loop over a sequence? l Loops are powerful  Format? Syntax?  Errors? for x in seq: do something to x do another thing l Loops in Lightbot?  Implicit l Loops in string.split(), loops in file.read()  Again implicit: Advantages? Disadvantages? l What about conditional execution? Next week!