Download presentation
Presentation is loading. Please wait.
Published byAllan Hunter Modified over 8 years ago
1
CompSci 101 Introduction to Computer Science January 15, 2015 Prof. Rodger 1
2
Don’t forget the rule You can’t sit in the last two rows That’s you! 2
3
Announcements Want a permission number to add course? –Fill out form on course web page (main page) Reading for next time, do RQ 3 Assignment 1 due Tuesday, Jan 20 APT 1 is out and due on Thursday, Jan 22 Today – Problem Solving, Python practice, solve an APT 3
4
Starting with Python Variable –Name of a storage location – holds a value = to assign a value to a variable Type –Different types of data –A variable can stores 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) 4
5
Eclipse – Three ways to run 1.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 2.Snarf an APT and run in Eclipse 3.Run interactively –Open PyDev console –Execute each line as typed –Code not saved 5
6
Variables, Types, Expressions? a = 5 b = 4 c = "fred" print c print a + b * 3 print (a + b) * 3 print a / b print a / (b * 1.0) 6
7
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 7
8
Latanya Sweeney I am a computer scientist with a long history of weaving technology and policy together to remove stakeholder barriers to technology adoption. My focus is on "computational policy" and I term myself a "computer (cross) policy" scientist. I have enjoyed success at creating technology that weaves with policy to resolve real-world technology-privacy clashes. http://latanyasweeney.org/ Identify 87% of US population using (dob,zip,gender). Director of Harvard Data Privacy Lab, instrumental in HIPAA because if de-identification work, currently Chief Technologist FTC 8
9
Function – define vs call def functionName(parameters): block def sum(a, b): return a+b Call function sum(7, 4) sum(“a”, “cat”) Advantages –Repeat code, call multiple times –Flexible, call with different arguments 9
10
Demo 2 In Eclipse write a file with a function and run Stuff.py 10
11
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 11
12
Demo 3 on Solving APT BMI Write your code in Eclipse Snarf the apt testing materials –Create the python file in apt folder –Write your code Run in Eclipse or Run on the web 12
13
Skills and Practice for Game Playing http://www.youtube.com/watch?v=AEBbsZK39es $193, $540, $820, $700, $749. Are these reasonable? Why? 13
14
I'm thinking of a number … bit.ly/101S15-0113-03 You guess. I'll tell you high, low, or correct –Goal: guess quickly, minimal number of guesses –Number between 1 and 100… –Number between 1 and 1000… Can you describe an algorithm, instructions, that would allow someone to use your instructions to play this game correctly. Start with 1 and 100, but ideally your instructions work with 1 and X 14
15
Analyzing the binary search algorithm Is the algorithm correct? –Try it, again, and again and … –Reason about it: logically, informally, … How efficient is the algorithm? –How many guesses will it take (roughly, exactly) –Should we care about efficiency? When do we really care about efficiency? –Examples? 15
16
Anderson Applegate Bethune Brooks Carter Edwards Foggle Griffin Holhouser Jefferson Klatchy Morgan Munson Narten Oliven Parken Rivers Roberts Stevenson Thomas Wilson Woodrow Yarbrow Find Narten 16
17
Anderson Applegate Bethune Brooks Carter Edwards Foggle Griffin Holhouser Jefferson Klatchy Morgan Munson Narten Oliven Parken Rivers Roberts Stevenson Thomas Wilson Woodrow Yarbrow X X X Find Narten Found! How many words did we look at? 17
18
Searching for words If we had a million words in alphabetical order, how many would we need to look at worst case to find a word? 18
19
Searching for words If we had a million words in alphabetical order, how many would we need to look at worst case to find a word? 20 1,000,000 500,000 250,000 125,000 62,500 31,250 15,620 7812.5 3906 1953 976.56 488. 244 122 61 30 15 7.5 3.75 1.875 If you are clever, Cut the number of numbers to look at in half over and over again, Then only 18 numbers to look at worst case 19
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.