CS Paper 1 Flashcards

1
Q

string manipulation -length

A

-length of string =
len(string)
spaces are a valid character

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

string manipulation-position

A
  • stringname>.index(string)
    -stringname>.find(string)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

string manipulation - substring

A

-string[start:end]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

string manipulation - concatenation

A

cocatenation - act of joining two/more separate strings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

string manipulation - character-character code

A

supply ord function. ‘a’ returns ASCII coe 97

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

string manipulation - character code to character

A

supply the chr function, ‘97’ returns ASCII character ‘a’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

string maniupulation commands

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

random number generator

A

-import random
print (random.randint(1,6))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

exception handling

A

-process in programming that responds to the occurrence of exceptions(error) during the execution of a program
-goal is to provide a way to detect and report error occurences so that appropriate action can be taken

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

exception handling -solution

A

-try clause and jump to except clause when there is an error instead of crashing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

subroutines

A

-block of code given an identifiable name within a program
-use them to break down a larger problem into series of smaller, more manageable problems so they are easier to: code, debug,reuse

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

procedures

A

block of code
that takes in 0,1/more parameters
performs a set task

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

function

A

block of code
takes in 0/1/more parameters
performs a set task
returns a value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

advantages of subroutines

A

-Programs easier to write
-Programs easier to debug
-Creates reusable components
-Functions can be grouped in a Library for easy reuse across multiple programs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

local variables

A

-Declared inside a Subroutine
-Only accessible by that subroutine
-Created when subroutine is called
-Destroy destroyed when subroutine ends

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

global variable

A

-Declared at the top of a program outside of subroutines
-Accessible throughout program
-Created when program starts
-Destroy destroyed when program ends