ENGG1810 Flashcards

1
Q

What is a function?

A

A sequence of re-usable code which executes a function when it is called

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. What kind of brackets are used for: lists, tuples, sets, dictionaries
A

Lists: [ ]
Tuples: ( )
Sets: { }
Dictionaries: { }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. What function can you use to display the group type?
A

print(type (collection_name ))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. What does len() do? WWYUI
A

len() is used to show the length of a collection.
Could use it for checking how many items are in a set.
Can use it for calculating the average in a collection.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. What is the index of an item in a list?
A

An index is the unique identifier of an item in a list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. Does indexing start from 0 or from 1
A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. What are the qualities of a list v set v tuple v dictionary? When would you use each one?
A

List - mutable, accepts duplicates, ordered, indexed
Set - mutable, no duplicates, unordered, unindexed
Tuple - immutable, accepts duplicates, ordered, indexed
Dictionary - ordered (key:value sets), no duplicates, semi-mutable?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. How do you slice a range of indexes from a list. Create a list of 5 or more items. Show what the 1st 3 items are.
A
  • Use square brackets and colon.
  • Number in front of colon is the lowest and included index, number after is the highest and excluded index

e.g. list=[red,orange,yellow,green,blue]

1st 3 items:
list[0:3] OR list[:3]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. Show everything before the 4th item of a list
A

print(list[:3])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. Show everything after the 2nd item on the list.
A

print(list[2:])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. Why would indexing be useful?
A
  • Allows you to differentiate between duplicate values
  • Helps you find items within a certain position of a collection vs specific values. So if you have items in order, indexing makes it easier to find items from a certain position in a collection.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
  1. How do you use negative indexing?
A
  • Negative indexing starts from the end - if the list was circular, -1 would be a step in the anti-clockwise direction
    Negative indexing could be useful if your list keeps getting longer, and you only want the latest/most recent value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  1. How do you add items to the end of a list?
A

list_name.append(“new_item_name”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
  1. How do you add items to a certain index of a list?
A

list.insert(index,”item name”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
  1. How do you remove items from a list a) based on name; b) based on index?
A

list. remove(“item”)

list. pop(index)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
  1. How do you change the value of an item on a list?
A

list_name[specific_index] = ‘value to update’

- Ie. I want to change the value of this indexed item on specified list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q
  1. How would you change values in a tuple?
A

Convert to a list first, change values, then convert back to a tuple

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q
  1. How do you search for items in a set?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q
  1. How do you search for a value in a dictionary?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q
  1. How do you define a dictionary?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q
  1. What is the general structure of an if/else block?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q
  1. What is the general structure of an if/elif/else block?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q
  1. How do you convert between tuples and lists?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q
  1. What does a “while” loop do?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q
  1. How do you set up a “while” loop?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q
  1. When does a “while” loop end?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q
  1. Draw an example flowchart for a “while” loop for a) one with a specified upper limit b) one with no defined end
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q
  1. What are the 6 different relational operators
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q
  1. What is the different between “=” and “==”
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q
  1. What are the 3 different logical operators? How do they work?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q
  1. How do you instantly stop an endless loop?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q
  1. Why do endless loops happen?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q
  1. Compare “break” and “continue” functions. Why would you use either one?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q
  1. What does a “for” loop do? Which data collections can you use it with?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q
  1. How does a “for” loop turn out when you use a string?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q
  1. How does a “for” loop turn out when you use a set?
A

Using a set - data will come out in random order, as set data is unordered

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q
  1. What are the 3 different ways you can use a “for” loop with a dictionary?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q
  1. Plot a graph!
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q
  1. How do you change the linestyle and marker on a graph?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q
  1. How do you change the font colour and style on a graph?
A

ans

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

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q
  1. How would you end a “while” loop prior to the condition being false?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q
  1. How would you skip to the next iteration of a loop?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q
  1. Which function would you use if you wanted to make a string into a vertical list of characters?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q
  1. What is the different between using a for() with dictionary, and using print() by itself?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q
  1. What would stop a while loop from working?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q
  1. What function would you use for definite iteration?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q
  1. What function would you use for indefinite iteration?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
49
Q
  1. What is meant by a multi-dimensional collection?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q
  1. What is matplotlib.pyplot used for?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q
  1. How do you combine graph plotting with loops
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
52
Q
  1. How do you open a text file in Python
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
53
Q
  1. What are the different read modes?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
54
Q
  1. What does open(file,mode) do?
A

ans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
55
Q
  1. How would you start the graph plot with loop function?
A

ans

56
Q
  1. What is the difference between 1-dimensional and 2-dimensional data
A

ans

57
Q
  1. How would you create a plot using matplotlip for 1 dimensional data?
A

ans

58
Q
  1. What are subplots() used for?
A

ans

59
Q
  1. How do you set up a subplot()
A

ans

60
Q
  1. What does the read(size) function do?ans
A

size will specify the number of characters displayed in a text i.e. if you put size=5, it will only print the first 5 characters of text

61
Q
  1. How do you add line breaks to strings?
A

ans

62
Q
  1. What does n/ do?
A

ans

63
Q
  1. What does the split function do? How do you use it?
A

ans

64
Q
  1. How would you break up a string into parts, based on the presence of a character?
A

ans

65
Q
  1. What does it mean to concatenate a string?
A

ans

66
Q
  1. What does filename.write() do?
A

ans

67
Q
  1. How to test for exceptions in Python?
A

ans

68
Q
  1. How does try()/except() work?
A

ans

69
Q
  1. How do the not/and/or relational operators work?
A

ans

70
Q
  1. How do you search for a character in a list, tuple or set?
A

ans

71
Q
  1. How do you search for matching items within a group or set?
A

ans

72
Q
  1. How do you check if specified data has only alphanumeric characters?
A

ans

73
Q
  1. Outline the structure of the range function - what happens when you put 1, 2, or 3 numbers in?
A

ans

74
Q
  1. What are the order of operations between not, and, or?
A

ans

75
Q
  1. What is a function?
A

ans

76
Q
  1. How do you define a new function?
A

ans

77
Q
  1. Outline the structure of a function.
A

ans

78
Q
  1. Compare parameter and argument
A

ans

79
Q
  1. What is a function call?
A

ans

80
Q
  1. How do you set more than one argument in a function?
A

ans

81
Q
  1. What is a default parameter value?
A

ans

82
Q
  1. What is a return statement?
A

as

83
Q
  1. Compare print() and return ()
A

ans

84
Q
  1. How do you create global and local variables?
A

ans

85
Q
  1. Can you use a return statement outside of a function?
A

ans

86
Q
  1. What does the global() function do?
A

ans

87
Q
  1. How do you print a specific value of a dictionary?
A

Can search for a value by searching for its key: group_name[‘key_name’]= value

88
Q
  1. How do you use the bar() function.
A

ans

89
Q
  1. Plot a graph using the bar() function.
A

ans

90
Q
  1. How do you create a new list using values from a dictionary?
A

ans

91
Q
  1. How to plot a horizontal bar graph
A

ans

92
Q
  1. Value labels for bars
A

ans

93
Q
  1. Plt.barh function
A

as

94
Q
  1. Can you read the same text twice within a single block of code?
A

ans

95
Q
  1. How do you use the f.seek function?
A

ans

96
Q
  1. How do you split text into lines?
A

ans

97
Q
  1. How do you draw a bar vs scatter vs line graph
A

ans

98
Q
  1. How do you define a function to draw a graph?
A

ans

99
Q
  1. How do you create an animated graph?
A

ans

100
Q
  1. What types of errors can you get in Python? Differentiate between them.
A

ans

101
Q
  1. What is a syntax error?
A

ans

102
Q
  1. What is a runtime error?
A

ans

103
Q
  1. What is a logical error?
A

ans

104
Q
  1. What is a built-in exception?
A

ans

105
Q
  1. How do you handle many exceptions?
A

ans

106
Q
  1. What is a “finally” exception
A

ans

107
Q
  1. What is an else exception?
A

ans

108
Q
  1. How do you raise an exception?
A

ans

109
Q
  1. How do you use an elif function with a graph
A

ans

110
Q
  1. Which library do you import to get an animated graph?
A

ans

111
Q
  1. What does textline refer to?
A

ans

112
Q
  1. Will a “finally” function be executed if a try block doesn’t work?
A

ans

113
Q
  1. Will an else function work if there are any exceptions in a try block?
A

ans

114
Q
  1. How do you make a list from the keys or values of a dictionary?
A

ans

115
Q
  1. Can you put an if/else loop in a new defined function?
A

ans

116
Q
  1. What happens when you nuse a split function but don’t specify an argument?
A

ans

117
Q
  1. What function do you need to animate?
A

ans

118
Q

Compare scalar, tensor, vector, matrix

A

Any single numerical value is known as Scalar.
•1-dimensional arrays are known as Vectors.
•2-dimensional arrays are known as Matrices.
•N-dimensional arrays are known as Tensor. (N > 2)

119
Q
  1. Compare libraries/packages/modules
A

ans

120
Q
  1. How do you create a module?
A

ans

121
Q
  1. How do you import a module?
A

ans

122
Q
  1. Compare script vs module
A

ans

123
Q
  1. What does the min/max function do?
A

ans

124
Q
  1. What does the abs function do?
A

ans

125
Q
  1. What does the round function here?
A

ans

126
Q
  1. What does the pow function do?
A

ans

127
Q
  1. How do you get the square root of a number?
A

ans

128
Q
  1. Math.ceil()
A

ans

129
Q
  1. Math.floor()
A

ans

130
Q
  1. Math.pi()
A

ans

131
Q
  1. How do you get pi in python?
A

ans

132
Q

What is NumPy?

A

ans

133
Q

How do you define a scalar, vector, matrix, and tensor?

A

ans

134
Q

What happens when you add arrays

A

ans

135
Q

Numpy indexing

A

ans

136
Q

How do you draw a sin/cos graph with NumPy

A

ans