CompSci 101 Introduction to Computer Science January 26, 2016 Prof. Rodger compsci 101, spring 20161.

Slides:



Advertisements
Similar presentations
CompSci 101 Introduction to Computer Science January 22, 2015 Prof. Rodger compsci101 spring151.
Advertisements

CompSci 101 Introduction to Computer Science February 3, 2015 Prof. Rodger Lecture given by Elizabeth Dowd.
Python Programming: An Introduction to Computer Science
Lists Introduction to Computing Science and Programming I.
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
Chapter 2 Writing Simple Programs
CS61A Lecture 2 Functions and Applicative Model of Computation Tom Magrino and Jon Kotker UC Berkeley EECS June 19, 2012.
CompSci 101 Introduction to Computer Science January 13, 2015 Prof. Rodger compsci 101 spring
CompSci 101 Introduction to Computer Science January 20, 2015 Prof. Rodger compsci 101, spring
CompSci 100e Program Design and Analysis II January 18, 2011 Prof. Rodger CompSci 100e, Spring20111.
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 2.
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,
Introduction. 2COMPSCI Computer Science Fundamentals.
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.
This Week The string type Modules print statement Writing programs if statements (time permitting) The boolean type (time permitting)
CSE 131 Computer Science 1 Module 1: (basics of Java)
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.
Python Programming Using Variables and input. Objectives We’re learning to build functions and to use inputs and outputs. Outcomes Build a function Use.
CompSci 101 Introduction to Computer Science September 23, 2014 Prof. Rodger.
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.
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 6 Introduction to Computer Science November 1, 2011 Prof. Rodger.
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 November 8, 2011 Prof. Rodger.
CompSci 101 Introduction to Computer Science November 18, 2014 Prof. Rodger.
CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151.
INLS 560 – F UNCTIONS Instructor: Jason Carter.
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 March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.
CompSci 101 Introduction to Computer Science February 10, 2015 Prof. Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were.
CompSci 101 Introduction to Computer Science January 28, 2016 Prof. Rodger compsci101 spring161.
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 February 4, 2016 Prof. Rodger compsci101 spring161.
CompSci 101 Introduction to Computer Science November 11, 2014 Prof. Rodger CompSci 101 Fall Review for exam.
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 24, 2016 Prof. Rodger compsci 101, spring
CompSci 101 Introduction to Computer Science March 8, 2016 Prof. Rodger.
CompSci 101 Introduction to Computer Science April 14, 2016 Prof. Rodger compsci101 spring161.
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.
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Prof. Jeremy.
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.
Chapter 2 Writing Simple Programs
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Based on slides by Shawn.
Exam #1 You will have exactly 30 Mins to complete the exam.
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 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
Functions CIS 40 – Introduction to Programming in Python
Compsci 101, Intro to Python
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Compsci 6/101: PFTW Review how APTs and Python work, run
Introduction to Computer Science
Functions, Procedures, and Abstraction
Presentation transcript:

CompSci 101 Introduction to Computer Science January 26, 2016 Prof. Rodger compsci 101, spring 20161

Announcements Reading and RQ 4 due next time Assignment 1 due today, Asgn 2 out APT 1 is due Thursday Lab 2 this week Today –more APT practice –functions, parameters –Names, types and values compsci 101, spring 20162

Functions return values Most functions return values –Sometimes used to make things simpler, but returning values is a good idea def inch2centi(inches): return 2.54*inches xh = inch2centi(72) def pluralize(word): return word + "es" pf = pluralize("fish") compsci 101, spring 20163

What is an APT? BMI APTBMI APT Automated/Algorithmic Problem Testing –Write one function, 2-30 lines, solve a problem –Tested automagically in Eclipse or the browser –Lots of test cases – test test test Start simple, build toward more complex –What is a function? A function call? –What is a parameter? Argument? –How do you run/execute a program 4compsci 101, spring 2016

Demo Solving APT BMI Write your code in Eclipse –Create python file –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 –Tests on lots of examples, Debug, fix –Get all GREEN – Green dance! Submit on APT page –README form too 5

Function Detective compsci 101, spring 20166

Results of Code Analysis For details on plurals: 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! 7

Organization matters compsci 101, spring 20168

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 9

Python – Names and Types Names vs abstractions –What is –What is Types are important –What is foo.pdf, foo.mp4, foo.jpg, foo.wav –Do the file extensions guarantee file type? Python – what types are these? first = "Susan" x = 6 y = 3.4 compsci 101, spring

Strings Sequence of characters in quotes "I" + 'Love' + '''Python''' "I" 'Love' '''Python''' 'ILovePython' String operators: concatenation (+), repeat(*) Precedence? "a" + "b" + "c" * 3 'abccc' Precedence? "a" + "b" "c" * 3 'abcbcbc' 11compsci 101, spring 2016

Strings Sequence of characters in quotes (same result) "I" + 'Love' + '''Python''' "I" 'Love' '''Python''' 'ILovePython' String operators: concatenation (+), repeat(*) Precedence? "a" + "b" + "c" * 3 'abccc' Precedence? "a" + "b" "c" * 3 'abcbcbc' 12compsci 101, spring 2016

Function def functionName(parameters): block of code Parameters – place holder, will store value passed in Arguments – values in the call, that you pass to the function to use as input 13compsci 101, spring 2016

Function – return or print? 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) sum(4,7) answer = sum(4,7) print hw(“a”) hw("Sue") 14compsci 101, spring 2016

Function – return or print? 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) sum(4,7) answer = sum(4,7) print hw(“a”) hw("Sue") 15compsci 101, spring 2016 x x

Old MacDonald Song Write a Program to print this song 16

Function OldMacPig() compsci 101, spring

Rest of Code Function OldMacCow –Replace “pig” with “cow” –Replace “Oink” with “Moo” Code to start: compsci 101, spring

Discuss how to make code better bit.ly/101sp a Describe in words how you can make the code better? More efficient? –Fewer lines of code? –Use more functions? –Discuss your changes. What advantages do the changes you make have? compsci 101, spring

Demo – Old Mac improvements What does the horse say? What does the cow say? What does the fox say? compsci 101, spring

Assignment 2 out Totem poles –printing heads –functions compsci 101, spring

Names, Types and Values bit.ly/101sp compsci 101, spring