Python Summative 2 Flashcards

1
Q

a sequence of instructions that performs a task

A

Functions

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

input(), type(), print() are what

A

built-in functions

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

used to make function will be defined

A

def()

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

Components of a function

A

Function Header
Function Body
Descriptive String

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

starts with a keyword def

A

Function header

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

allows us to also define our own functions

A

Python

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

followed by a function name

A

Function Header

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

followed by a pair of parentheses with the input parameter inside and ends with a colon ( : )

A

Function Header

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

variables that the user need to supply to a function as input and can be manipulated in the body of the function

A

Parameters

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

where the step-by-step instructions to be executed upon calling the function was placed

A

Function Body

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

it is important to note that the instructions in the body of function must be indented, and in the case of multiple instructions, all the instructions must be of the same indent

A

Function Body

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

at the end of _____, it can return some output.

A

Function Body

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

it is important to note that the instructions in the body of function must be _____

A

indented

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

some functions can return some output or not

A

TRUE

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

After defining the function header, an optional ______ be placed in the middle of triple single or triple double quotes

A

Descriptive String

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

This can be used to describe in more detail the task that will be performed by the function

A

Descriptive String

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

The ______ is also accessed by the command help()

A

Descriptive String

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

The descriptive string is also accessed by the command

A

help()

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

If the user inputs a number instead of a string, Python will still execute the function until something goes wrong

A

TRUE

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

At the end of the function, the keyword ______ was used to indicate the variable that will be output by the function.

A

return

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

Can we access the variables that was defined inside functions?

A

No

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

When defining a function, Python creates a separate listing of variables for it.

A

TRUE

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

When defining a function, Python creates a separate listing of variables for it. This list of variables can only be accessed during the execution of the function

A

TRUE

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

the variables that are local to the function is not part of the variables tracked across the whole Python notebook

A

TRUE

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

Strings and tuples are immutable data types.

A

True

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

Using this function returns the number of characters in the string.

A

len()

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

Lists in python are mutable data type.

A

True

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

The variables that are local to the __________ are not part of the variables tracked across the _______ Python notebook.

A

function, whole

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

Given the string below, what is the output of the code snippet?

a_string = “ Bubalus mindorensis”

a_string[9:]

A

‘mindorensis’

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

Strings can only be implemented by enclosing it with single quotations.

A

False

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

Lists and Tuples are mutable data types.

A

False

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

These are the three built-in functions in Python as mentioned in the lesson.

A

input, type, print

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

Function headers are followed by a ________ of parentheses with the input parameter inside and ends with a_______.

A

pair, colon

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

Which of the following is the reason for declaring with def( )?

A

it allows you to make new function

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

It can be used to explain in detail the task that will be performed by the function.

A

descriptive string

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

It is where the step-by-step instructions to be executed are written.

A

function body

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

Python gives the user freedom to assign variables to different data types.

A

TRUE

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

Given the string below, what is the output of the code snippet?

a_string = “ Bubalus mindorensis”

a_string[-1]

A

’s’

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

Dictionaries are indexed by ________.

A

keys

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

Given the string below, what is the output of the code snippet?

a_string = “ Bubalus mindorensis”

a_string[4:9]

A

‘alus ‘

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

Given the string below, what is the output of the code snippet?

def hello(name=”BSCSDS”,hour=-1):

print("Hello " + name + "!")

hour = 2**11

if hour == -1:

    print("Good day!")

else:

    if hour <= 1200:

        print("Good morning!")

    elif hour <= 1700:

        print("Good afternoon!")

    else:

        print("Good evening!")

hello()

A

Hello BSCSDS! Good evening!

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

function header

A

This was followed by a pair of parentheses with the input parameter inside and ends with a colon.

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

Given the string below, what is the output of the code snippet?

a_string = “ Bubalus mindorensis”

a_string[8]

A

’ ‘

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

When defining a function, Python creates a separate listing of variables for it.

A

TRUE

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

represent plain text

A

Strings

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

should be enclosed in either single or double quotations

A

Strings

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

get the number of characters in the string

A

len()

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

indicates the location of the individual characters in a string

A

index

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

Type in the name of the string and then its index enclosed in square brackets to access a character given its index

A

TRUE

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

Accessing a part of the string through index enclosed in square brackets

A

slicing

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

Notice that the end index specified is until 9 but the output only returned until index 8 This means that the range specified in square bracket excludes the upper bound

A

TRUE

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

The syntax for slicing in Python is ________

A

[start:end:step]

53
Q

This is indicated by the symbol + performed on the strings

A

concatenation

54
Q

As indicated in the TypeError output, it cannot concatenate a string with an integer

A

TypeError

55
Q

As indicated in the TypeError output, it cannot concatenate a string with an _____

A

integer

56
Q

Using a built-in function _____ to convert an integer value

A

str()

57
Q

is an object that has various methods that can be used to manipulate it

A

strings

58
Q

In Python, a string is an object that has various _____ that can be used to manipulate it

A

methods

59
Q

To have an idea of how a certain string method works, use the command _____

A

help()

60
Q

Using string methods does not change the original string

A

TRUE

61
Q

is a sequence of values

A

Lists

62
Q

the values in a list are called its

A

elements or items

63
Q

is defined by enclosing its items in square brackets, separated by commas

A

Lists

64
Q

a list can hold any type of data

A

TRUE

65
Q

can hold any type of data

A

Lists

66
Q

Operations of Lists:

A

use of len()
use of (negative) index
slicing
concatenation (+)

67
Q

to whether an exists in in a list

A

in

68
Q

checking if an item is present

A

in

69
Q

Methods of Lists:

A

append()
insert()
remove()

70
Q

add an item at the end of list

A

append()

71
Q

insert an item at a given index

A

insert()

72
Q

remove first occurrence of a string

A

remove()

73
Q

also a sequence of values

A

Tuple

74
Q

Using a pair of parentheses (), elements are separated by commas

A

Tuple

75
Q

In Tuple, Operations like getting the length, indexing, slicing, using + and in are the same as those in strings and lists

A

TRUE

76
Q

_____ are mutable, ____are immutable

A

Lists, Tuples

77
Q

items can be changed in-place

A

Mutable

78
Q

items that cannot be changed in-place

A

Immutable

79
Q

Lists are usually _____, tuples are usually ______.

A

homogeneous, heterogeneous

80
Q

is a general version of a list

A

dictionary

81
Q

In a list, the indices have to be integers, in a dictionary, they can be (almost) any type.

A

TRUE

82
Q

In a list, the indices have to be _____, in a dictionary, they can be ______

A

integers, (almost) any type.

83
Q

Dictionaries are indexed by ________.

A

keys

84
Q

comprises of key-value pairs, and each key maps to a comma-separated key:value pairs

A

dictionary

85
Q

are declared by (comma-separated) key:value pairs enclosed in square brackets

A

dictionaries

86
Q

method to get all the keys in a dictionary

A

keys()

87
Q

method to get all the values in a dictionary

A

values()

88
Q

method to get all the key-value pairs in a dictionary

A

items()

89
Q

The ______ operator when used on dictionaries search occurrence from the keys

A

in

90
Q

We can use the command ______ to access a list of dictionaries keys

A

list()

91
Q

What is the output of the following:
len(“Hey there!”)

A

10

92
Q

What is the output of the following:
a_string = “Hey there!”
a_string[0]

A

H’

93
Q

What is the output of the following:
a_string = “Hey there!”
a_string[-1]

A

!’

94
Q

What is the output of the following:
a_string = “Hey there!”
a_string[4:9]

A

there’

95
Q

What is the output of the following:
a_string = “Hey there!”
a_string[4:9:2]

A

tee’

96
Q

What is the output of the following:
a_string = “Hey there!”
a_string[4:]

A

there!’

97
Q

What is the output of the following:
a_string = “Hey there!”
a_string[:4]

A

Hey ‘

98
Q

What is the output of the following:
a_string = “Hey there!”
a_string[::2]

A

Hytee’

99
Q

What is the output of the following:
a_string = “Hey there!”
a_string[4:-1]

A

there’

100
Q

What is the output of the following:
a_string = “Hey there!”
a_string[::-2]

A

!ereht yeH’

101
Q

What is the output of the following:
a_string = “Budget: “
another_string = “4000”
print(a_string + “ “ + another_string)

A

Budget: 4000

102
Q

What is the output of the following:
msg = “FEU Institute of Technology
msg.upper()

A

FEU INSTITUTE OF TECHNOLOGY’

103
Q

What is the output of the following:
msg = “FEU Institute of Technology
msg.count(“e”)

A

2

104
Q

What is the output of the following:
msg = “FEU Institute of Technology
msg.replace(“ institute of technology”, “TECH”)

A

FEU Institute of Technology

105
Q

What is the output of the following:
numbers = [10, 20, 30, 40, 50]
states = [“solid”, “liquid”, “gas”]
list_of_lists = [numbers, states]
list_of_lists

A

[[10, 20, 30, 40, 50], [‘solid’, ‘liquid’, ‘gas’]]

106
Q

What is the output of the following:
numbers = [10, 20, 30, 40, 50]
states = [“solid”, “liquid”, “gas”]
mixed_type_list = [1, “way”, 2, “say”, 3, “words”]
states[1]

A

liquid’

107
Q

What is the output of the following:
numbers = [10, 20, 30, 40, 50]
states = [“solid”, “liquid”, “gas”]
mixed_type_list = [1, “way”, 2, “say”, 3, “words”]
states[-1]

A

gas’

108
Q

What is the output of the following:
numbers = [10, 20, 30, 40, 50]
states = [“solid”, “liquid”, “gas”]
mixed_type_list = [1, “way”, 2, “say”, 3, “words”]
states[0]

A

solid’

109
Q

What is the output of the following:
numbers = [10, 20, 30, 40, 50]
states = [“solid”, “liquid”, “gas”]
mixed_type_list = [1, “way”, 2, “say”, 3, “words”]
states[:2]

A

[‘solid, ‘liquid’]

110
Q

What is the output of the following:
numbers = [10, 20, 30, 40, 50]
states = [“solid”, “liquid”, “gas”]
mixed_type_list = [1, “way”, 2, “say”, 3, “words”]
len(states)

A

3

111
Q

What is the output of the following:
numbers = [10, 20, 30, 40, 50]
states = [“solid”, “liquid”, “gas”]
mixed_type_list = [1, “way”, 2, “say”, 3, “words”]
mixed_type_list + states

A

[1, ‘way’, 2, ‘say’, 3, ‘words’, ‘solid’, ‘liquid’, ‘gas’]

112
Q

What is the output of the following:
exam_scores = [90, 83, 85, 77]
exam_scores.append(91)
exam_scores

A

[90, 83, 85, 77, 91]

113
Q

What is the output of the following:
pokemon = [“Pikachu”, “Oshawott”, “Goodra”]
pokemon.insert(1, “Oshawott”)
pokemon

A

[‘Pikachu’, ‘Oshawott’, ‘Oshawott’, ‘Goodra’]

114
Q

What is the output of the following:
pokemon = [“Pikachu”, “Oshawott”, “Goodra”]
pokemon.insert(1, “Oshawott”)
pokemon.remove(“Oshawott”)
pokemon

A

[‘Pikachu’, ‘Oshawott’, ‘Goodra’]

115
Q

What is the output of the following:
list(“Watermelon”)

A

[‘W’, ‘a’, ‘t’, ‘e’, ‘r’, ‘m’, ‘e’, ‘l’, ‘o’, ‘n’]

116
Q

What is the output of the following:
FEU_School_list = [“Alabang”, “Diliman”, “Tech”]
“ “.join(FEU_School_list)

A

Alabang Diliman Tech’

117
Q

What is the output of the following:
FEU_School_list = [“Alabang”, “Diliman”, “Tech”]
“_“.join(FEU_School_list)

A

Alabang_Diliman_Tech’

118
Q

What is the output of the following:
FEU_School_list = [“Alabang”, “Diliman”, “Tech”]
FEU_string = ““.join(FEU_School_list)
FEU_string.split(“
”)

A

[‘Alabang’, ‘Diliman’, ‘Tech’]

119
Q

What is the output of the following:
a_tuple = (1, 1000, 2, 1000, 3, 1000)
len(a_tuple)

A

6

120
Q

What is the output of the following:
a_tuple = (1, 1000, 2, 1000, 3, 1000)
a_tuple[2:]

A

(2, 1000, 3, 1000)

121
Q

What is the output of the following:
a_tuple = (1, 1000, 2, 1000, 3, 1000)
a_tuple.count(1000)

A

3

122
Q

What is the output of the following:
sample_dict = {“one”:”uno”, “two”:”dos”, “three”:”tres”}
sample_dict[“one”]

A

uno’

123
Q

What is the output of the following:
sample_dict = {“one”:”uno”, “two”:”dos”, “three”:”tres”}
sample_dict[“two”]

A

dos’

124
Q

What is the output of the following:
sample_dict = {“one”:”uno”, “two”:”dos”, “three”:”tres”}
sample_dict.keys()

A

dict_keys([‘one’, ‘two’, ‘three’])

125
Q

What is the output of the following:
sample_dict = {“one”:”uno”, “two”:”dos”, “three”:”tres”}
sample_dict.values()

A

dict_values([‘uno’, ‘dos’, ‘tres’])

126
Q

What is the output of the following:
sample_dict = {“one”:”uno”, “two”:”dos”, “three”:”tres”}
sample_dict.items()

A

dict_items([(‘one’, ‘uno’), (‘two’, ‘dos’), (‘three’, ‘tres’)])

127
Q

What is the output of the following:
delicacies = {}
delicacies[“puto”] = “Calasiao”
delicacies[“bibingka”] = “Vigan”
delicacies[“ensaymada”] = “Bulacan”
delicacies

A

{‘puto’ : ‘Calasiao’, ‘bibingka’ : ‘Vigan’, ‘ensaymada’ : ‘Bulacan’}

128
Q

What is the output of the following:
a_list = [(“puto”, “Calasiao”), (“bibingka”, “Vigan), (“ensaymada”, “Bulacan)]
dict(a_list)

A

{‘puto’ : ‘Calasiao’, ‘bibingka’ : ‘Vigan’, ‘ensaymada’ : ‘Bulacan’}

129
Q

What is the output of the following:
delicacies = {}
delicacies[“puto”] = “Calasiao”
delicacies[“bibingka”] = “Vigan”
delicacies[“ensaymada”] = “Bulacan”
list(delicacies)

A

[‘puto’, ‘bibingka’, ‘ensaymada’]