-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex37.py
120 lines (107 loc) · 4.84 KB
/
ex37.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# KEYWORDS
# and - boolean expression that compares statements and returns True if all are true
# del - deletes a variable or list item by index
# from - reference a module to import from
# not - boolean expression that reverses the boolean value
# while - loop that continues looping while condition is true
# as - allows you to specify a name for a imported method
# elif - follows an if statement. if the if is false, elif is evaluated next
# global - declares a variable as 'global' this can be done from inside or outside a function
# Allows you to bring a variable into a function as a non-argument
# or modify a script variable from a function
# or - boolean statement that returns true if either of it's conditions is true
# with - typically used to open a variable/file then perform an operation on it then close
# assert - tests a condition, if false, the error code is returned
# else - if all ifs and elifs in an if statement are false, else is evaluated
# if - a loop statement that runs code if a condition is met
# pass - statement used to keep code running. used in indents after colons to prevent error
# yield - returns a generator value. Advances to the next yield when next() is called
# break - breaks out of a loop when executed. can be part of an 'if' statement
# except - used in try-except looks. if exception specified after except occurs, runs the loop
# import - imports a module or a method from a module specific in from
# print - prints to command line
# class - a template that defines a type of object that can have attributes, methods, etc
# exec - executes code stored in a string or object or file
# in - boolean expression that checks if the item is contained "in" the item after the statement
# raise - raises an error code and passes it to code upstream
# continue - breaks loop then returns control to the top of the current iteration of loop
# finally - final loop component that can be added to try/except and receives control
# no matter what when the other components are run
# is - checks if two variables are pointing to the same object in memory
# return - returns a value from a function
# def - defines a function or method
# for - begins a for loop. for x in list[]:
# lambda - allows creation of compact functions. object = lambda x: x + 1
# try - use in a try/except loop. It will attempt to run code, except will be triggered
# if the code returns an error flag
# DATA TYPES
# True - boolean statement that some condition is true
# False - boolean statement that some condition is false
# None - a value to assign to throw a name away
# strings - a text sentence or word, or even character
# numbers - integers are the main type used to store numbers.
# floats - float numbers have a decimal point in them
# lists - lists contain a series of values ['a', 1, 'b'] list[0]
# STRING ESCAPE SEQUENCES
# \\ Backslash escape
# \' single quote escape
# \" double quote escape
# \a ASCII BEL alert character. Makes a cute little alarm
# \b ASCII backspace
# \f ASCII form feed - advance to next page
# \n new line
# \r carriage return - returns to front of line
# \t tab escape character
# \v vertical tab character. moves down a line at the same tab location
# STRING FORMATS
# %d - decimal format
# %i - decimal format
# %o - unsigned octal
# %u - unsigned decimal
# %x - hexidecimal lowercase
# %X - hexidecimal uppercase
# %e - Floating point hexidecimal format lowercase
# %E - floating point hexidecimal format uppercase
# %f - floating point decimal format
# %F - floating point decimal format
# %g - same as 'e' if exponent is greater than -4
# %G - same as 'E' if exponent is greater than -4
# %c - Single character... accepts integer or single character string
# %r - converts any python argument using repr... used for debugging
# %s - string
# %% - no argument. % character is printed
# OPERATORS
# + Add
# - Subtract
# * multiply
# ** exponent
# / division
# // floor division (no decimal float
# % modulus, returns the remainder after division
# < less than
# > greater than
# <= less than or equal to
# >= greater than or equal to
# == equal to
# != not equal to
# <> old way to do not equal to
# ( ) parentheses... evaluate this first. Used to make generator types
# [ ] brackets... used to define list types
# { } dictionary type list
# @ decorator
# , comma... used to separate list items and function arguments
# : colon... use to declare loops and functions
# . period, used to call methods in modules
# = equals, used to assign values to names
# ; semicolon - separates statements on the same line
# += increment operator by amount (shorthand)
# -= subtract operator by amount
# *= multiply operator by amount
# /= divide operator by amount
# //= floor divide operator
# %= modulus operator
# **= exponent shorthand operator
# READING CODE EXERCISE
# Github adventure game template
# See ex37codereading\
# contains commented code and flowchart of how I think it works