Computer Science part 2 Flashcards Preview

Tiger Cards > Computer Science part 2 > Flashcards

Flashcards in Computer Science part 2 Deck (19)
Loading flashcards...
0

What will the following produce?

>>>num=4
>>>for index in range(num):
print(num+1, end with " ")

>>>num=4
>>>for index in range(num):
print(num+1, end with " ")

5 5 5 5

1

True or false? Why?

Lists cannot share the same memory location

False

Lists can share the same memory location because they are mutable

2

Do the following share the same memory location?

Address1=["hello"]
Address2=["hello"]

No because address2 has its own list

3

Define alias

Same thing but different name

4

True or false? Why?

String cannot share the same memory location

True because

Strings are immutable therefore they cannot share the same memory location

5

Does the following have the same value?

Name1="Mike"
Name2="Mike"

Yes

6

Does the following have the same memory location?

Name1="Mike"
Name2="Mike"

No

7

Define function(3 parts to it)

• we call a function by name
• a function that takes an argument
• a function that returns a results

8

Define "function definition"

Make a new function and runs a sequence of statements that run when the function is called

9

True or false?

The name of the function does not follow the same rule as naming a variable

False

Function naming follows the same rules as naming a variable

10

Define function object

The name of the newly created functions

11

What will happen to the following?

def print_hi:
print("hi")
type(print_hi)

def print_hi:
print("hi")
type(print_hi)

class 'function'

12

Define parameters

Arguments assigned to a variable are called parameters

13

Define fruitful function

Functions that act and return values

14

Define void function

Functions that perform an action but return no values

15

What will happen to the following?

>>>type(None)

>>>type(None)
class 'NoneType'

16

What will happen to the following?

>>>result=print_twice('bing')
bing
bing
>>>print(result)

>>>result=print_twice('bing')
bing
bing
>>>print(result)
None

17

Define execution flow

Programming flowing from top to bottom

18

Why divide a program into bits and bits of function? (4 points)

• makes your program easier to debug and read
•allows us to divide our long program and debug and assemble them back into a whole
•eliminate repetitive code
• reusable