CompSci 101 Introduction to Computer Science

Slides:



Advertisements
Similar presentations
INTRODUCTION Chapter 1 1. Java CPSC 1100 University of Tennessee at Chattanooga 2  Difference between Visual Logic & Java  Lots  Visual Logic Flowcharts.
Advertisements

CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
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.
Recitation 1 Programming for Engineers in Python.
CS61A Lecture 2 Functions and Applicative Model of Computation Tom Magrino and Jon Kotker UC Berkeley EECS June 19, 2012.
Python Programming Fundamentals
CompSci 101 Introduction to Computer Science January 20, 2015 Prof. Rodger compsci 101, spring
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 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.
Dynamic Web Pages & JavaScript. Dynamic Web Pages Dynamic = Change Dynamic Web Pages are web pages that change. More than just moving graphics around.
Module 3 Fraser High School. Module 3 – Loops and Booleans import statements - random use the random.randint() function use while loop write conditional.
CompSci 101 Introduction to Computer Science September 23, 2014 Prof. Rodger.
Compsci 6/101, Spring More on Python, Tools, Compsci 101 l APTs, Assignments, Tools  APT: Algorithmic Problem-solving and Testing  How to get.
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
Compsci 101, Fall Plan For The Day (PFTD) l Practice solving problems  Some solved with a computer, some with Python  Differences in solving.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
CompSci 101 Introduction to Computer Science January 28, 2016 Prof. Rodger compsci101 spring161.
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 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 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.
Foundations of Programming: Java
Introduction to Programming
Introduction to Programming
Lesson 06: Functions Class Participation: Class Chat:
Development Environment
Whatcha doin'? Aims: To start using Python. To understand loops.
Exam #1 You will have exactly 30 Mins to complete the exam.
CompSci 101 Introduction to Computer Science
Introduction to Eclipse
CS1022 Computer Programming & Principles
CompSci 101 Introduction to Computer Science
Introduction to Python
Introduction to Programming
CompSci 101 Introduction to Computer Science
Variables, Expressions, and IO
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Functions CIS 40 – Introduction to Programming in Python
JavaScript Functions.
Functions.
IPC144 Introduction to Programming Using C Week 2 – Lesson 1
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Introduction to Programming
Teaching London Computing
Loops CIS 40 – Introduction to Programming in Python
Introduction to Programming
Compsci 6/101: PFTW Review how APTs and Python work, run
Bryan Burlingame 13 February 2019
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Introduction to Value-Returning Functions: Generating Random Numbers
CISC101 Reminders All assignments are now posted.
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
Introduction to Programming
CISC101 Reminders Assignment 3 due today.
Class code for pythonroom.com cchsp2cs
IS 135 Business Programming
Introduction to Python
Unit Testing.
Presentation transcript:

CompSci 101 Introduction to Computer Science Sep 5, 2017 Prof. Rodger

Announcements Reading and RQ3 due next class Assignment 1 due today! See the catch up schedule – for everyone! APT 1 out and due on Tuesday, Sep 12 Need a pin to add class – fill out form Exam accommodations – fill out form Lab 2 this week Today –Variables and Functions, Solve an APT, Problem solving cps101 fall 2017

The Online Textbook Text part describes Python Version 3 My version of the book, Python Version 2 just in the code boxes Main Differences: Divide, not using // Use / for division, 7/2 will be 3 7.0/2 will be 3.5 Print We will use: print x Not using with parenthesis: print(x) cps101 fall 2017

Barbara Liskov (one of) first women to earn PhD from compsci dept Stanford 1968 Turing award in 2008 Programming Languages CLU “It's much better to go for the thing that's exciting. But the question of how you know what's worth working on and what's not separates someone who's going to be really good at research and someone who's not. There's no prescription. It comes from your own intuition and judgment.” Created a new programming language (CLU). Not widespread use, but it had new features that are now in object oriented languages like Java and C++. She also did work on operating systems Her ideas helped form the foundation for modern programming languages such as Java, which are designed to make use of self-contained modules of data and instructions that can be developed once and reused to many different ends. In 1961, she got her undergrad degree in Mathematics. Instead of pursuing an advanced degree in math after college, she got a job as a computer programmer at Mitre, a not-for-profit organization in the Boston area that conducts federally funded research in systems engineering and information technology. At the time, hardly anyone was trained in computer science. From Mitre, Liskov moved on to work on a Harvard University project that sought to automatically translate English sentences into something a computer could understand. Though natural-language processing is a problem that computer scientists are still working on, back then people expected that it would be solved in a few years. She decided she wanted to go to grad school so she applied to graduate school at Princeton and got a postcard from them that said “They didn’t accept female students.”. So she went to Stanford. cps101 fall 2017

Starting with Python Variable Type operators in Python for numbers Name of a storage location – holds a value = to assign a value to a variable Type Different types of data A variable can store data of a certain type int, float, str operators in Python for numbers Arithmetic: + - * / % ** Built-in functions: pow, abs, round, int, float example: pow(2,3) + round (1.6)

Starting with Python http://bit.ly/101f17-0905-1 cps101 fall 2017

Eclipse – Three ways to run Write program and store in file Create a PyDev project – a folder for programs Create a PyDev module for each program (file) Run in console Create an APT in Eclipse and run on web Run interactively Open PyDev console Execute each line as typed Code not saved cps101 fall 2017

Demo: Run interactively in Eclipse PyDev Console If Console window is not showing then Click on Window, Show View, Console Then at the bottom of Eclipse, click here: Select PyDev Console, Python Console cps101 fall 2017

Variables, Types, Expressions? print a + b * 3 print (a + b) * 3 print a / b print a / (b * 1.0) a = 5 b = 4 print b a = a + b print a c = "fred" print c Use shoeboxes to step through what is happening with these statements cps101 fall 2017

Examples of functions cps101 fall 2017 See the next slide. These are three examples of functions seen by students. Go over these quickly, understand from next slide why these pictures are here cps101 fall 2017

Functions explained In a calculator, sqrt: number in -> number out What is domain, what is range? In MSWord, word count: document -> number Domain is word doc, range is integer In browser, web: URL -> HTML formatted "page" Domain is valid URL, range is HTML resources In Python we see similar structure! cps101 fall 2017

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 Body of function must be indented Point out the parameters cps101 fall 2017

Demo In Eclipse write a file with a function and run it stuff.py def sum(a, b): return a+b if __name__ == '__main__': print sum(3,5) print sum(1,4) Try strings cps101 fall 2017

APTs cps101 fall 2017

What is an APT? BMI 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 Google BMI and show the calculator on the web. Type in funny numbers weight 50 or weight 450 The www.cdc.gov gives error for 7 ft 8 in 110 lbs – ask to check your entries cps101 fall 2017

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 Submit on APT page REFLECT form too

cps101 fall 2017

APT: BMI (cont) cps101 fall 2017

Write a program to print the Old MacDonald Song Write a Program to print this song cps101 fall 2017

Function OldMacPig() cps101 fall 2017

Rest of Code Function OldMacCow Code to start: Replace “pig” with “cow” Replace “Oink” with “Moo” Code to start: cps101 fall 2017

Discuss how to make code better bit.ly/101f17-0905-2 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? cps101 fall 2017

Demo – Old Mac improvements What does the horse say? What does the cow say? What does the fox say? Google “what does the fox say” and show part of video Ring-ding-ding-ding cps101 fall 2017

Lab 2 this week Write a program to print a song Work on the Gravity APT cps101 fall 2017