GEOG 376 Study Guide - Midterm Guide: Concatenation, For Loop, Boolean Data Type

75 views5 pages
GEOG 376 Midterm Review
I. Intro to Computer Programming
A. The Crash Course
A computer program is a collection of instructions that performs a specific task
when executed by a computer. It requires programs to function and is usually written
in a programming language
Compiled programming: Humans write source code which is then compiled by a
compiler which produces machine codea form consisting of instructions that the
computer can directly execute (e.g., C++ language)
Interpreted programming: a computer program may be executed with the aid of an
interpreter (e.g., Python).
Geographers need to program for automation (Increase efficiency, Avoid human
error, kill boredom), Customization, and modeling
B. Program development Cycle
1. Define the problem (be sure you understand what the program should do, what the
output should be and what input you need.)
2. Design the solution (find a logical sequence of steps that solve the problem, i.e.
develop an algorithm.)
3. Code: write actual code in a given computer language.
4. Test and debug: test find errors in the program, debug correct the errors
5. Write documentation: organize the materials that describe the program.
Commenting should occur as an on-going process rather than be the last step of the
program. But it should be finalized once the program is completed.
II. Data Types, Variables, and Operators
A. Values and Variables
Values are one of the fundamental things that can be manipulated by a program.
Variables can store values in the memory of the computer and to name them for
later retrieval.
Variables must begin with a letter, be alphanumeric, and have no reserved words.
Integers and Floats are commonly assigned to variables (Integers can only be
whole numbers while floats are decimal number and need a float command to be
treated as such and can store up to 15 decimal places)
1. Bits, Bytes, and ASCII code
All values are stored as a sequence of bits with a single binary value of either 0 or
1. Bit multiples are called bytes which are usually made up of 8 bits in most
computer systems.
B. Strings
String: a sequence of one or more characters (letters, numbers, symbols) that can
be stored in a variable. It is an immutable sequence, meaning it is unchanging
Serves as an important building block to programming since text is such a common
form of data that we use in everyday life.
Strings can exists within either single quotes or double quotes, but whatever quotes
you use should be consistent within the program (Do NOT start with a single quote
and end with a double quote.)
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 5 pages and 3 million more documents.

Already have an account? Log in
Concatenation: joining strings together end-to-end to create a new string. This is
done through the “+” operator. (Although the + operator is meant for addition, it is
used as a join operator in strings)
Spaces make no difference to operators, but it will not work for variable names
C. String Formatting and Functions
String literals are what we see in the source code of a computer program, including
the quotation marks. A string value is what we see when we call the print ()
function and run the program.
Case function: str.title ( ) will capitalize the first letter of each word and lowercase
the rest. str.upper ( ) and str.lower ( ) will return a string with all the letters of an
original string converted to upper or lowercase letters.
Length: The len () function returns the number of characters in a string. It can also
be used to determine where a character index is.
Join: Concatenate two strings, but in a way that passes one string through another.
Split: Splits strings and the result is a list containing two elements
III. Collection Data Types
A. Indexing and Slicing
Each of a string’s characters correspond to a number starting with 0. Since each
character in a string has a corresponding index number, it allows us to access and
manipulate strings at the character level, and isolate one of the characters in a
string with square brackets.
A positive index number counts from the left of the string (even though it starts at
0) while a negative index number begins at the right of the string as -1.
Slicing is used to call out a range of characters from the string by creating a range
of index numbers separated by a colon [x:y] (the first index number is where the
slice starts (inclusive), and the second index number is where the slice ends
(exclusive).) If we want to include either end of the string, we can omit one of the
numbers in the string[n:n] syntax
B. Lists
Lists are mutable (a.k.a. changeable), ordered sequence of elements
Defined as square brackets [ ]
Each element or value that is inside of a list is called an item.
Stride is a type of slicing technique that refers to which interval to display after
the first item is retrieved from the list.
a. Various list commands
List.append(x): adds an item(x) to the end of a list
List.insert(i, x): takes two arguments, with i being the index position you would
like to add an item to, and x being the item itself.
List.extend: Used to combine more than one list
List.remove: Can remove an item from a list. It only removes the first
occurrence of a value, not all of them if there are multiples
List.pop: Returns the item to the given index position from the list and then
removes that item.
List.count: Will return the number of times the value x occurs within a specified
list. (Useful when there is a long list with a lot of matching value.)
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 5 pages and 3 million more documents.

Already have an account? Log in

Document Summary

Intro to computer programming: the crash course, a computer program is a collection of instructions that performs a specific task when executed by a computer. Commenting should occur as an on-going process rather than be the last step of the program. But it should be finalized once the program is completed. Data types, variables, and operators: values and variables, values are one of the fundamental things that can be manipulated by a program. Variables can store values in the memory of the computer and to name them for later retrieval: variables must begin with a letter, be alphanumeric, and have no reserved words. It can also be used to determine where a character index is: join: concatenate two strings, but in a way that passes one string through another, split: splits strings and the result is a list containing two elements. Iii: indexing and slicing, each of a string"s characters correspond to a number starting with 0.