comp 171: data types john barr. review - what is computer science? problem solving recognizing...
TRANSCRIPT
![Page 1: COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving Recognizing Patterns If you can find a pattern in the way you solve](https://reader036.vdocument.in/reader036/viewer/2022082818/56649f145503460f94c28451/html5/thumbnails/1.jpg)
COMP 171: Data Types
John Barr
![Page 2: COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving Recognizing Patterns If you can find a pattern in the way you solve](https://reader036.vdocument.in/reader036/viewer/2022082818/56649f145503460f94c28451/html5/thumbnails/2.jpg)
Review - What is Computer Science?
Problem Solving
Recognizing Patterns
If you can find a pattern in the way you solve different instances of a problem, you can create an algorithm so the computer can solve the problem for you.
![Page 3: COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving Recognizing Patterns If you can find a pattern in the way you solve](https://reader036.vdocument.in/reader036/viewer/2022082818/56649f145503460f94c28451/html5/thumbnails/3.jpg)
Review - What is Computer Science?
An Algorithm
Step-by-step procedure to solve the problem from beginning (start state) to end (end state)
Sequential
Some steps can repeat
High level: only list important details
![Page 4: COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving Recognizing Patterns If you can find a pattern in the way you solve](https://reader036.vdocument.in/reader036/viewer/2022082818/56649f145503460f94c28451/html5/thumbnails/4.jpg)
Values
Fundamental building block in a programming language
Values are the “things” that we save and manipulate
There are only a few basic types of values …but we can make our own types of
values
![Page 5: COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving Recognizing Patterns If you can find a pattern in the way you solve](https://reader036.vdocument.in/reader036/viewer/2022082818/56649f145503460f94c28451/html5/thumbnails/5.jpg)
Data Types in Python
Integers whole numbers, positive or negative (5, 42, -7)
FloatsDecimal numbers (3.14159, 88.3 -5.7)
Stringssequences of characters (‘dog’, “cat”, ‘’’rat’’’,
‘17’, “23.5” )
classes and types are the same thing (for now)
Can use one two or three quotes
![Page 6: COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving Recognizing Patterns If you can find a pattern in the way you solve](https://reader036.vdocument.in/reader036/viewer/2022082818/56649f145503460f94c28451/html5/thumbnails/6.jpg)
Variables A way to name a place in memory for data Legal Names:
No spaces Can’t start with a number
start with letter or underscore Can’t use keywords
middle of "Variables, Expressions and Statements" chapter for list
e.g., class, int Don’t use symbols
$, %, # illegal
![Page 7: COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving Recognizing Patterns If you can find a pattern in the way you solve](https://reader036.vdocument.in/reader036/viewer/2022082818/56649f145503460f94c28451/html5/thumbnails/7.jpg)
Variables
Takes a value, and assigns it a variable
age = 18 #puts the int 18 into the variable age
name = "Joe" #puts the string "Joe" into the variable name
Can be reused age = 87 changes the value in the variable age
![Page 8: COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving Recognizing Patterns If you can find a pattern in the way you solve](https://reader036.vdocument.in/reader036/viewer/2022082818/56649f145503460f94c28451/html5/thumbnails/8.jpg)
Variables
What’s currently in a variable Interpreter: just type variable name and
returnProgram: use the print() function
![Page 9: COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving Recognizing Patterns If you can find a pattern in the way you solve](https://reader036.vdocument.in/reader036/viewer/2022082818/56649f145503460f94c28451/html5/thumbnails/9.jpg)
Input
Takes a string in from the keyboard always a string, even if you enter a number
temp = input() #gets a string and saves into variable temp
![Page 10: COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving Recognizing Patterns If you can find a pattern in the way you solve](https://reader036.vdocument.in/reader036/viewer/2022082818/56649f145503460f94c28451/html5/thumbnails/10.jpg)
Input
Problem: input always returns a string. What if we want to get a number?
age = input(“Enter your age”) type(age)
Must convert to the type we want int (string), float(string), str(int or float)
![Page 11: COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving Recognizing Patterns If you can find a pattern in the way you solve](https://reader036.vdocument.in/reader036/viewer/2022082818/56649f145503460f94c28451/html5/thumbnails/11.jpg)
Debugging – finding errors / faults
syntax errors
runtime errors
semantic errors
![Page 12: COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving Recognizing Patterns If you can find a pattern in the way you solve](https://reader036.vdocument.in/reader036/viewer/2022082818/56649f145503460f94c28451/html5/thumbnails/12.jpg)
Comments
Programs can get very long and convoluted.
Sometimes we’d like to put in some words to explain what we’re doing
python comments start with the # character. everything on the line after the # is ignored
![Page 13: COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving Recognizing Patterns If you can find a pattern in the way you solve](https://reader036.vdocument.in/reader036/viewer/2022082818/56649f145503460f94c28451/html5/thumbnails/13.jpg)
Practice
Write a program that creates a variable for your name and a variable for your age, and prints a sentence like this:
Toby is 32
![Page 14: COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving Recognizing Patterns If you can find a pattern in the way you solve](https://reader036.vdocument.in/reader036/viewer/2022082818/56649f145503460f94c28451/html5/thumbnails/14.jpg)
Practice
Add code to calculate and print your age in decades:
That's 3.2 decades
![Page 15: COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving Recognizing Patterns If you can find a pattern in the way you solve](https://reader036.vdocument.in/reader036/viewer/2022082818/56649f145503460f94c28451/html5/thumbnails/15.jpg)
Practice
Get first name from the keyboard
![Page 16: COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving Recognizing Patterns If you can find a pattern in the way you solve](https://reader036.vdocument.in/reader036/viewer/2022082818/56649f145503460f94c28451/html5/thumbnails/16.jpg)
Practice
Get age from the keyboard