CompSci 101 Introduction to Computer Science

Slides:



Advertisements
Similar presentations
Python Programming Chapter 1: The way of the program Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
Advertisements

CS61A Lecture 2 Functions and Applicative Model of Computation Tom Magrino and Jon Kotker UC Berkeley EECS June 19, 2012.
An Introduction to Content Management. By the end of the session you will be able to... Explain what a content management system is Apply the principles.
CompSci 101 Introduction to Computer Science January 13, 2015 Prof. Rodger compsci 101 spring
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
CompSci 101 Introduction to Computer Science January 20, 2015 Prof. Rodger compsci 101, spring
Chapter 6 Functions -- QuickStart. "The Practice of Computing Using Python", Punch & Enbody, Copyright © 2013 Pearson Education, Inc. What is a function?
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 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.
Compsci 06/101, Fall What will we do today? l Practice solving problems  Solving problems without a computer  Is this different than solving.
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.
Compsci 06/101, Fall Compsci 6/101: Random debugging?!# l The joys and rewards of writing code to solve a problem  How do we know where to begin?
CompSci 101 Introduction to Computer Science September 23, 2014 Prof. Rodger.
CompSci 101 Introduction to Computer Science Sept. 9, 2014 Prof. Rodger President Brodhead speech graduation 2010 CompSci 101 Fall
Compsci 6/101, Spring More on Python, Tools, Compsci 101 l APTs, Assignments, Tools  APT: Algorithmic Problem-solving and Testing  How to get.
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.
CompSci 6 Introduction to Computer Science September 13, 2011 Prof. Rodger.
Compsci 101, Fall Plan For The Day (PFTD) l Practice solving problems  Some solved with a computer, some with Python  Differences in solving.
CompSci 101 Introduction to Computer Science January 28, 2016 Prof. Rodger compsci101 spring161.
The Development Process Compilation. Compilation - Dr. Craig A. Struble 2 Programming Process Problem Solving Phase We will spend significant time on.
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
CompSci 101 Introduction to Computer Science January 15, 2015 Prof. Rodger 1.
CompSci 6 Introduction to Computer Science September 27, 2011 Prof. Rodger CompSci 6 Fall
CompSci 101 Introduction to Computer Science February 16, 2016 Prof. Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were.
CompSci 101 Introduction to Computer Science March 8, 2016 Prof. Rodger.
CompSci 101 Introduction to Computer Science February 5, 2015 Prof. Rodger Lecture given by Elizabeth Dowd compsci101 spring151.
PROBLEM SOLVING WARM-UP Fill in the spaces using any operation to solve the following (!, (), -/+,÷,×): = 6.
CSC 108H: Introduction to Computer Programming Summer 2011 Marek Janicki.
CompSci 101 Introduction to Computer Science Sept 13, 2016 Prof. Rodger compsci101 fall161.
CompSci 4 Java 1 Apr 2, 2009 Prof. Susan Rodger. Announcements Assignment 7 questions? –Beware having two events that kick in at the same time! –Beware.
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Based on slides by Shawn.
Lesson 06: Functions Class Participation: Class Chat:
Development Environment
More about comments Review Single Line Comments The # sign is for comments. A comment is a line of text that Python won’t try to run as code. Its just.
Introduction to Computing Science and Programming I
Exam #1 You will have exactly 30 Mins to complete the exam.
CompSci 101 Introduction to Computer Science
A Playful Introduction to Programming by Jason R. Briggs
Introduction to Eclipse
COSC 1306 COMPUTER SCIENCE AND PROGRAMMING
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Introduction to Python
CompSci 6 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Corpus Linguistics I ENG 617
CompSci 230 Software Construction
CompSci 101 Introduction to Computer Science
Compsci 101, APTs and Sequences and Selection
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
String Output ICS 111: Introduction to Computer Science I
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
First Python Program Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An.
Introduction to Computer Programming
Lesson 06: Functions Class Chat: Attendance: Participation
CISC101 Reminders All assignments are now posted.
CMPT 120 Lecture 3 - Introduction to Computing Science – Programming language, Variables, Strings, Lists and Modules.
James Wei Professor Peck 9/20/2013
Functions, Procedures, and Abstraction
Presentation transcript:

CompSci 101 Introduction to Computer Science Sept. 7, 2017 Prof. Rodger compsci 101, fall 2017

Announcements Reading and RQ 4 due next time Asgn 2 out, APT 1 is due Tuesday Add class/change sections? – see forms tab on www.cs.duke.edu/courses/compsci101/fall17 Today - FTIS functions, parameters Names, types and values First Thursday in September compsci 101, fall 2017

Assignment 2 out Totem poles Note: You have different requirements printing heads Functions Note: You have different requirements compsci 101, fall 2017

REVIEW: Solving APT BMI Write your code in Eclipse Create python file - with Module:Main Name of file important – case matters name of function important – cut and paste this Write your code Test a few examples in Eclipse Run online on using APT Tester Test on examples, Debug, fix, get all GREEN Submit on APT page must run again, then check score Fill out REFLECT form too REVIEW what they need to do to turn in the APT

Organization matters https://www.youtube.com/watch?v=1ve57l3c19g This is an all time favorite. I think when Robert de Niro looks at Cybil Shepard in the clip it's clear that he's infatuated with her. It's a long time ago. We are still infatuated with teaching and coding and we hope they will be. We also want to be organizized with building programs. Movie Taxi Driver compsci 101, fall 2017

APT organization, Code organization You’ve written the BMI.py APT Where is that module? How do you test it? PyDev console, but then must import it Adding print statements in BMI.py to test Putting sentences together in order… “Once upon a time…” “It was the best of times…” “Aujord’hui ma maman est morte” Putting code together in order Takes judgment and experience The second bullet is about famous 'first lines'. You don't need a good first line in a program. You need all the code to work together. Unlike a book where sentences can be skipped, you can't skip things in a program.. The 'judgment and experience' could lead to a famous quote "good judgment comes from experience, experience comes from bad judgment' compsci 101, fall 2017

Running and Understanding Code Need Python compiler/interpreter We're using Canopy, includes libraries Need an editor development environment We use Eclipse and PyDev, open source and widely used, Ambient is Duke Plugin You need experience thinking and coding and debugging ideas and code: Installing the suite of tools can be cumbersome Persist, Perservere, Get Help, start over  Spending time at the beginning to get your envinroment set up – we will help you with that. Course is not compsci 101, fall 2017

Understanding terminology: code Move from "Hello World" to "Hello Around the World" Look at Python, code, libraries Learning (reviewing) terminology about Python print "hello world" Hello around the world Ask students to say hello in another language than English, Then show them this program to read in greetings from a file f = open("hello.txt") for line in f: print line compsci 101, fall 2017

Hello around world code http://bit.ly/101f17-0907-1 compsci 101, fall 2017

Hello from the web bit.ly/101f17-0907-2 import urllib2 if __name__ == '__main__': url = "http://www.cs.duke.edu/courses/compsci101/fall17/data/hello.txt" f = urllib2.urlopen(url) for line in f: print line compsci 101, fall 2017

Hello from the Web in Python We open a file, and we open a URL Syntax slightly different, concept is similar Real-world differences between files and URLs? Must adhere to syntactic rules of Python Naming, whitespace, : or . or ( or ) or [ or ] Must adhere to semantic rules of Python Can't loop over anything, more rules to follow f = open("hello.txt") Why is the syntax different, does it have to be urlopen instead of open? Know, but the differences can be useful, in making it clear to reader what kind of thing is being opened URL or file. Where do dots go, where do ()’s go

Hello from the Web in Python We open a file, and we open a URL Syntax slightly different, concept is similar Real-world differences between files and URLs? Must adhere to syntactic rules of Python Naming, whitespace, : or . or ( or ) or [ or ] Must adhere to semantic rules of Python Can't loop over anything, more rules to follow f = open("hello.txt") f = urllib2.urlopen("http://nytimes.com") Why is the syntax different, does it have to be urlopen instead of open? Know, but the differences can be useful, in making it clear to reader what kind of thing is being opened URL or file. Where do dots go, where do ()’s go

Functions return values Most functions return values Sometimes used to make things simpler, but returning values is a good idea def inch2centi(inches): answer = 2.54*inches return answer xh = inch2centi(72) Simple examples, these will be in snarf-for-class examples – tinker with – cat we will need more powerful Return is usually the last statement. You may have other statements such as an assignment statement in there. def pluralize(word): return word + "es" pf = pluralize("fish") compsci 101, fall 2017

Functions can print info Some functions only print info Note there is no return statement in the function def helloPerson(name): print "hello" + name helloPerson("Susan") helloPerson("Ademola") Simple examples, these will be in snarf-for-class examples – tinker with – cat we will need more powerful There is no value to return!!! compsci 101, fall 2017

Simple Python Functions http://bit.ly/101f17-0907-3 Answer these questions based on thinking, don't run any code Why do we need functions? Manage complexity of large programs Test and develop code independently Reuse code in new contexts: create APIs! You don't need to understand the program, but we could run the code and that would help. But answer the questions without running the code! compsci 101, fall 2017

Function – return or print? bit.ly/101f17-0907-4 Example function that returns a value def sum(a, b): return a+b Example function that prints def hw(name): print "Hello " + name Call Functions print sum(4,7) name = hw(“Sue”) answer = sum(4,7) hw(“Sue”) sum(4, 7) print hw(“Jo”) Point out the parameters and arguments

Function – return or print? bit.ly/101f17-0907-4 Example function that returns a value def sum(a, b): return a+b Example function that prints def hw(name): print "Hello " + name Call Functions print sum(4,7) name = hw(“Sue”) answer = sum(4,7) hw(“Sue”) sum(4, 7) print hw(“Jo”) Point out the parameters and arguments x x x

Function Detective http://bit.ly/101f17-0907-5 compsci 101, fall 2017

Results of Code Analysis For details on plurals: http://bit.ly/1N49u6b How did we call pluralize many times? Loop. What is an alternative? What does the 'if' statement do? Selects a code block to execute (more next week) If you have a question? Write and run code! Might have other things to note based on responses from class. Might want to run some calls of 'pluralize'. Can snarf it, add to list, try a few other things