ENGG1810 Flashcards

(136 cards)

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
2. How do you set up a "while" loop?
ans
26
3. When does a "while" loop end?
ans
27
4. Draw an example flowchart for a "while" loop for a) one with a specified upper limit b) one with no defined end
ans
28
5. What are the 6 different relational operators
ans
29
6. What is the different between "=" and "=="
ans
30
7. What are the 3 different logical operators? How do they work?
ans
31
8. How do you instantly stop an endless loop?
ans
32
9. Why do endless loops happen?
ans
33
10. Compare "break" and "continue" functions. Why would you use either one?
ans
34
11. What does a "for" loop do? Which data collections can you use it with?
ans
35
12. How does a "for" loop turn out when you use a string?
ans
36
13. How does a "for" loop turn out when you use a set?
Using a set - data will come out in random order, as set data is unordered
37
14. What are the 3 different ways you can use a "for" loop with a dictionary?
ans
38
15. Plot a graph!
ans
39
16. How do you change the linestyle and marker on a graph?
ans
40
17. How do you change the font colour and style on a graph?
ans
41
18. Command lines
ans
42
19. How would you end a "while" loop prior to the condition being false?
ans
43
20. How would you skip to the next iteration of a loop?
ans
44
21. Which function would you use if you wanted to make a string into a vertical list of characters?
ans
45
22. What is the different between using a for() with dictionary, and using print() by itself?
ans
46
23. What would stop a while loop from working?
ans
47
24. What function would you use for definite iteration?
ans
48
25. What function would you use for indefinite iteration?
ans
49
1. What is meant by a multi-dimensional collection?
ans
50
2. What is matplotlib.pyplot used for?
ans
51
3. How do you combine graph plotting with loops
ans
52
4. How do you open a text file in Python
ans
53
5. What are the different read modes?
ans
54
6. What does open(file,mode) do?
ans
55
7. How would you start the graph plot with loop function?
ans
56
8. What is the difference between 1-dimensional and 2-dimensional data
ans
57
9. How would you create a plot using matplotlip for 1 dimensional data?
ans
58
10. What are subplots() used for?
ans
59
11. How do you set up a subplot()
ans
60
12. What does the read(size) function do?ans
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
13. How do you add line breaks to strings?
ans
62
14. What does n/ do?
ans
63
15. What does the split function do? How do you use it?
ans
64
16. How would you break up a string into parts, based on the presence of a character?
ans
65
17. What does it mean to concatenate a string?
ans
66
18. What does filename.write() do?
ans
67
19. How to test for exceptions in Python?
ans
68
20. How does try()/except() work?
ans
69
21. How do the not/and/or relational operators work?
ans
70
22. How do you search for a character in a list, tuple or set?
ans
71
23. How do you search for matching items within a group or set?
ans
72
24. How do you check if specified data has only alphanumeric characters?
ans
73
25. Outline the structure of the range function - what happens when you put 1, 2, or 3 numbers in?
ans
74
26. What are the order of operations between not, and, or?
ans
75
1. What is a function?
ans
76
2. How do you define a new function?
ans
77
3. Outline the structure of a function.
ans
78
4. Compare parameter and argument
ans
79
5. What is a function call?
ans
80
6. How do you set more than one argument in a function?
ans
81
7. What is a default parameter value?
ans
82
8. What is a return statement?
as
83
9. Compare print() and return ()
ans
84
10. How do you create global and local variables?
ans
85
11. Can you use a return statement outside of a function?
ans
86
12. What does the global() function do?
ans
87
13. How do you print a specific value of a dictionary?
Can search for a value by searching for its key: group_name['key_name']= value
88
14. How do you use the bar() function.
ans
89
15. Plot a graph using the bar() function.
ans
90
16. How do you create a new list using values from a dictionary?
ans
91
17. How to plot a horizontal bar graph
ans
92
18. Value labels for bars
ans
93
19. Plt.barh function
as
94
20. Can you read the same text twice within a single block of code?
ans
95
21. How do you use the f.seek function?
ans
96
22. How do you split text into lines?
ans
97
1. How do you draw a bar vs scatter vs line graph
ans
98
2. How do you define a function to draw a graph?
ans
99
3. How do you create an animated graph?
ans
100
4. What types of errors can you get in Python? Differentiate between them.
ans
101
5. What is a syntax error?
ans
102
6. What is a runtime error?
ans
103
7. What is a logical error?
ans
104
8. What is a built-in exception?
ans
105
9. How do you handle many exceptions?
ans
106
10. What is a "finally" exception
ans
107
11. What is an else exception?
ans
108
12. How do you raise an exception?
ans
109
13. How do you use an elif function with a graph
ans
110
14. Which library do you import to get an animated graph?
ans
111
15. What does textline refer to?
ans
112
16. Will a "finally" function be executed if a try block doesn't work?
ans
113
17. Will an else function work if there are any exceptions in a try block?
ans
114
18. How do you make a list from the keys or values of a dictionary?
ans
115
19. Can you put an if/else loop in a new defined function?
ans
116
20. What happens when you nuse a split function but don't specify an argument?
ans
117
21. What function do you need to animate?
ans
118
Compare scalar, tensor, vector, matrix
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
1. Compare libraries/packages/modules
ans
120
2. How do you create a module?
ans
121
3. How do you import a module?
ans
122
4. Compare script vs module
ans
123
5. What does the min/max function do?
ans
124
6. What does the abs function do?
ans
125
7. What does the round function here?
ans
126
8. What does the pow function do?
ans
127
9. How do you get the square root of a number?
ans
128
10. Math.ceil()
ans
129
11. Math.floor()
ans
130
12. Math.pi()
ans
131
13. How do you get pi in python?
ans
132
What is NumPy?
ans
133
How do you define a scalar, vector, matrix, and tensor?
ans
134
What happens when you add arrays
ans
135
Numpy indexing
ans
136
How do you draw a sin/cos graph with NumPy
ans