programming 2 viva

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/56

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 12:04 PM on 10/13/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

57 Terms

1
New cards

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

2
New cards

define object

a bundle of data (variables called atrtibutes) plus the operations on that data (methods)

3
New cards

define class

a vlueprint or template many objects can be created from one class - defined with class key word

4
New cards

object oriented programming define

designing a program as lots of small objects work together - re-use code instead of rewriting it

5
New cards

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


6
New cards

define method overlapping

several methods iwht the same name but different parameter lists each behaving differently

7
New cards

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

8
New cards

define scope

where the variable can be used a variable made inside a function only exists inside that function

9
New cards

indetation define

marks which lines blond to a class

10
New cards

define sequence selection iteration

if elif else

11
New cards

define type casting

coverting a caluue to another type such as (int) (float) (string)

12
New cards

what does random.randint(1, 100) return

random whole number from 1 to 100 both included

13
New cards

difference between == and =

== compares, = assigns

14
New cards

what is method overloading

means several methods share a name but have different parameters

15
New cards

explain polymorphism

one name can take many forms behvaing differently depending on the object or data , overloading is a type of polymorphism

16
New cards

why call maximum number twice -

it only compares 2 numbers

17
New cards
  1. maximum number- what if two numbers are equal


num1> num2 is false, it returns num 2- same value, still correct

18
New cards
  1. 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)

19
New cards

whats the difference between break and quit

break leaves the loop while quit ends the whole program

20
New cards
  1. account balance- why a while loop not for loop?


we do not know the number of years in advance , loop until balance >/ target

21
New cards

how do you add interent

balance = balance + balance* interest rate

interest rate = 1.02

22
New cards
  1. 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

23
New cards
  1. days in month- how do you know if its a leap year


if it divisible by 4

24
New cards

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


25
New cards

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

26
New cards

why use overloading

  • it is simpler

  • more readable

    • same task done in different ways


27
New cards

define class attribute

class body- not in a method, the class and all objects- confined to a class

28
New cards

define istnace attribute

one object (each has its own copy- confised to an object of a class

29
New cards

define local

inside of a method , declared within a method scope

30
New cards

so variable attribute class objet

  • variable holds a value

  • attribute- a variable that belongs to an ebject

  • class - blue print

  • obejct - made from class



31
New cards

define static

belongs ot a class as a whole not to individual objects

32
New cards

define private

only accessible inside it sown class ab

33
New cards

define abstract

has no body you cant create objects

34
New cards

define variable

a named storage location in a computer program

  • ech variable hols a name an unique value



35
New cards

what is a primative data type

  • numbers strings files containers


36
New cards

define ltieral number

a literal number is the number types in and the decimal point decides integer or float

37
New cards

define constant variable

should nto be changed after the initial value has been assigned - declared suign all caps

38
New cards

what is a magic number

a number that eappears in your code without any further explaination

39
New cards

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 \.


40
New cards

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.


41
New cards

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.


42
New cards

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.


43
New cards

define function

collection of programming instructions or constructs that performa aparticular task


44
New cards

what does abs(x) do

gives the absolute value so that abs(-105) would give 105

45
New cards

what does round (x) do

rounds to the nearest integer

46
New cards

what does round (x,n) do

rounds to the nearest decimal place)

47
New cards

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

48
New cards

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

49
New cards

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



50
New cards

define string / string literal

sequence of characters

  • string literal denoets particular string with either ‘‘ or ““



51
New cards

explain index of a character

goe sfrom position 0 to position i

52
New cards

how can individual character in a string be accessed

subscript notation [] square brackets

53
New cards

how is the behaviour of an object given

through methods what

54
New cards

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

55
New cards

what does a method belong to

a type of object

you write objects first ehna dot then method name

56
New cards

Q: Does name.replace("Danny", "Daniel") change name?

A: No. It returns a new string, "Daniel Onah", and the original is untouched.


57
New cards