1/56
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
define modularity
splitting a program into small independent parts (function classes objects) where each part does one job - teams can build part in parallel and reuse them
define object
a bundle of data (variables called atrtibutes) plus the operations on that data (methods)
define class
a vlueprint or template many objects can be created from one class - defined with class key word
object oriented programming define
designing a program as lots of small objects work together - re-use code instead of rewriting it
method vs function define
both are named blocks of code with parameters that can return a value
a method is defined inside of a class
a function stands alone
define method overlapping
several methods iwht the same name but different parameter lists each behaving differently
polymorphism define
‘many forms’ the same method or operator name doing different things depending on the object adds numbers but joins strings - overloading is one example
define scope
where the variable can be used a variable made inside a function only exists inside that function
indetation define
marks which lines blond to a class
define sequence selection iteration
if elif else
define type casting
coverting a caluue to another type such as (int) (float) (string)
what does random.randint(1, 100) return
random whole number from 1 to 100 both included
difference between == and =
== compares, = assigns
what is method overloading
means several methods share a name but have different parameters
explain polymorphism
one name can take many forms behvaing differently depending on the object or data , overloading is a type of polymorphism
why call maximum number twice -
it only compares 2 numbers
maximum number- what if two numbers are equal
num1> num2 is false, it returns num 2- same value, still correct
number guesser - how do you limit to 5 guesses
start at 5 and drop by 1 per wrong guess or i in range (1,6)
whats the difference between break and quit
break leaves the loop while quit ends the whole program
account balance- why a while loop not for loop?
we do not know the number of years in advance , loop until balance >/ target
how do you add interent
balance = balance + balance* interest rate
interest rate = 1.02
days in month - how do you group months
or 4,6,9,11 → 30 while rest have 31 except for feb which has 28 on a leap 29
days in month- how do you know if its a leap year
if it divisible by 4
whats the difference between / // and %
/ normal division gives exact answer of 3.75
// floor division - gives whole number 3. with the decimal chopped of
% modulo - only the remainder of whats leftover
define overloading on more time for good measure - remeber maxnumebr
yo uhave one method with the same name but it can be called in different ways with different parameters
why use overloading
it is simpler
more readable
same task done in different ways
define class attribute
class body- not in a method, the class and all objects- confined to a class
define istnace attribute
one object (each has its own copy- confised to an object of a class
define local
inside of a method , declared within a method scope
so variable attribute class objet
variable holds a value
attribute- a variable that belongs to an ebject
class - blue print
obejct - made from class
define static
belongs ot a class as a whole not to individual objects
define private
only accessible inside it sown class ab
define abstract
has no body you cant create objects
define variable
a named storage location in a computer program
ech variable hols a name an unique value
what is a primative data type
numbers strings files containers
define ltieral number
a literal number is the number types in and the decimal point decides integer or float
define constant variable
should nto be changed after the initial value has been assigned - declared suign all caps
what is a magic number
a number that eappears in your code without any further explaination
Q: How can you split a long line of code over two lines?
A: Three ways: (1) break inside brackets ( ), (2) break after a comma inside a function call, or (3) end the line with a backslash \.
why does splitting a logn line of code work like that
A: The outer brackets are still open at the end of line 1, so Python knows the statement isn’t finished and keeps reading.
Q: What does a backslash \ at the end of a line do?
A: It joins that line to the next one, so Python reads them as one statement.
Q: What’s the danger with the backslash?
A: There must be nothing after it, not even a space or tab, or you’ll get an error.
define function
collection of programming instructions or constructs that performa aparticular task
what does abs(x) do
gives the absolute value so that abs(-105) would give 105
what does round (x) do
rounds to the nearest integer
what does round (x,n) do
rounds to the nearest decimal place)
what type of error doe sthe wrong number of arguments give you
type error e.g. abs (x,2), round has an optional second argument
so if we need a specific module from a livbarary how do we import it
jsut import a module from its libarary ‘from math import sqrt
explain libraries and modules
python’s standard libraries are orgnaised into modules
related functions and data types are grouped into the same module functions defined ina module must be explicitly loaded or impoirtant into your program before they can be used
define string / string literal
sequence of characters
string literal denoets particular string with either ‘‘ or ““
explain index of a character
goe sfrom position 0 to position i
how can individual character in a string be accessed
subscript notation [] square brackets
how is the behaviour of an object given
through methods what
what is a method
just like a function it is a collection of programming isntructions that carry out a particualr task , unlike a funcation which is a standalone operation a method can only be applied to an object of the type for which it was defined
what does a method belong to
a type of object
you write objects first ehna dot then method name
Q: Does name.replace("Danny", "Daniel") change name?
A: No. It returns a new string, "Daniel Onah", and the original is untouched.