• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/22

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

22 Cards in this Set

  • Front
  • Back
module
file containing definitions and statements intended for use in other python programs
have to be imported before used
deterministic machines
computers do the same predictable things everytime you give them the same instructions
real random
generated by a real world event likean atom decaying or not in the certain time
pseudorandom
not really random
seed(x)
provide the initial seed
x is usually integer
randrange(stop)
gets random integer from 0 to stop-1
randrange(start,stop)
gets random integer from start to stop-1
randrange(start,stop,step)
gets random numbers from start to stop-1 with a step size
random()
gets floating numbers in the range [0.0,1.0) useful for probabilities
seed(23)
it will always give you the same sequence of random numbers
no seed--use system time(different for every run)
function
a piece of code, does a specific job, has a name(an identifier) attached, has a list of things it uses to accomplish the task(parameters)
reasons to use/write functions
can be reused many times
makes it easier to work in teams
makes writing easier(put off details until necessary, easier to focus on one task at one time, write the program one function at a time)
makes testing easier
think of a function as a blackboard
all you need to know to use it : name, argument list, what it does or return
user doesn't need to know how the function does what it does
allows for easy behind the scenes changes of a function's implementation user doesn't need to know
two parts of function syntax
definition
call/invocation
syntax of definition
def identifier(parameter list):
definitions of functions are in the same file as the main function
body in a definition
all the lines after the def statement which are indented
may or may not end w/ a return statement(depends on whether the function returns a value or not)
parameter list
it can be empty or can have as many identifiers as desired, but don't go overboard(10 is too much)
can't be constant or expressions
position of the definition in a file doesn't matter, why?
functions run when they are called only
2 versions to call a function
doesn't return a value--non-fruitful
functionname(arguments) ex.tom.penup()
return a value--fruitful
variable = functionname(arguments)
or print(functionname(arguments))
(the call to the function i a part of another statement, not a standalone statement)
semantics of a function
first the call to the function is encountered in the code.
the code that is calling the code is suspended.
the arguments' values are copied into the place of the parameters, matching by order (called passing by value)
any local variables in the function are created as they are used
the code for the execution begins execution
finally the code for the function is finished
the return values are copied back to the calling code
the copies of argument that were put in the parameters are erased
any local variables in the function are erased
control is passed back to the calling code and the function is over
the calling code picks up where it left off
arguments
sometimes called the input of the function
different from using the input function to get data from keyboard
means that the value come from outside the function and go into the function via the parameter list
parameters
specify what the function needs to do it's work