Comp Sci General Questions Flashcards

1
Q

Python programs are…

A

Interpreted

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

Python is Case Sensitive…
True or False

A

True

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

PyCharm would be described as a…
A. Intergrated development

A

IDE(Integrated Development Environment)

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

How would you convert the string a = “HELLO” to lower case?
a) a.lower()
b) lower(a)
c) recase(a, TO_LOWER)
d) a.recase(TO_LOWER)

A

a.lower()

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

What would be the best way to find the length of the string a?
a) len(a)
b) a.length()
c) a[*]
d) Count each character

A

len(a)

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

What is the correct way to create a comment in Python?
a) // My comment
b) # My comment
c) /* My comment */

A

My comment

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

This is called
(2+3) == 2**(3)

A

Logical Expression

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

Which of the following is not a control statement in loops?
a) break
b) end
c) continue
d) none of the above
e) all of the above

A

end

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

In Python, what is the primary purpose of the “continue” keyword within a loop?

A

To skip the current iteration of the loop and move to the next one

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

What does the keys() method do?

A

Returns the keys in a dictionary as a list

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

What is the correct way to open the file grades.tsv for reading?

A

file = open(“grades.tsv”, “r”)

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

What is the correct way to read one full line from the already open file?

A

line = file.readline()

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

When reading a file, what will the readlines() method return when you reach the end of the file?

A

It will return an empty string(“”)

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

What should you do when you are done reading or writing a file?

A

Close the file wirh the .close() method

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

What does sep= method do?

A

Seperates the strings or lists with a new line or tab

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

How would you remove the extra spaces in the strings and convet the integers and floats correctly?

A

Use the .strip() to remove spaces and int() or float() to covert the strings

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

What does this method do?
lst = sorted(my_set, reverse=True)

A

Create a list from the following set sorted in decending order

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

What does lambda mean?

A

Used as an anonymous function inside another function. Can take any number of arguments, but only have one the expression

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

What does the union() method do?

A

Will return what both sets have

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

What does the difference() method do?

A

Will return what each set does not have

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

What does the intersection() method do?

A

Will get the common values that both sets has

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

What is the issuperset() method?

A

Returns turn if all items in the specified set exists in the original set

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

What is the issubset() method?

A

Returns True if all items in a set exists in the specified set, otherwise returns false

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

What is the order of the ouput of the following program?
nums = {5, 9, 2, 0, 1, 3, 4}
print(nums)

A

Sets are unordered, the order of the ouput is implementation dependent

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
What is the name of the constructor method in Python class?
__init__()
25
What is an instance variable in Python?
A variable defined inside a class to specific to each instance
26
In python, a function within a class definion is called a
method
27
Why is self used as the first parameter in class methods?
It is automatically assigned to the instance calling the method
28
True or False. To divide 2 integers to get an integer result, you can use %%
False
29
What is a way to write counter = counter + 1?
counter += 1
30
What is the main purpose of the "break" function?
To terminate the loop and exit it prematurely
31
What does the term variable scope mean?
The portion of code where a variable can be accessed and modified.
32
def is_mutiple(n): if n % 7 == 0: return n elif n % 3 == 0: return -1 elif n % 2 == 1: return True else: return False a) -1 b) False c) 21 d) True
c) 21
33
True or False. The keys() method in Python returns the keys of a dictionary as list.
True
34
True or False Lists in Python can contain elements of different data types.
True
34
What will this method do? print(my_dct[:-2])
It will print out all the elemets except the last 2
35
True or False. Dictionaries are always of a fixed sixed and cannot be changed.
False
35
True or False. In Python dictionaries, keys must be unique, but values can be duplicated.
True
35
What does this method do? print(prices[1][2])?
It will access the dictionary full of lists. Then it will access the first list and then acess the second element.
36
What will this line do? return None
None
37
Power supply, motherboard and CPU are examples of: A) Inputs and Outputs B) Internal Components C) Memory D) Storage E) None of the above
Internal components
38
The speed of the CPU is measured in: A) Byte B) Bit C) Hz (Hertz) D) None of the above
Hetz(Hz)
39
True or False. Hard Disk (HDD) and solid state drive (SSD) are examples of non-volatile storage
True
40
Which of the following is NOT an example of cloud storage. A) DropBox B) iCloud C) Solid State Drive D) Google Drive
Solid State Drive
41
In computers, data is represented using A) 0 , 1 B) 10 , 2 C) 0, 1, 10 D) 0, 1, 10, 2
0, 1
42
What is the representation used in X and Y X = 1010 Y=1110 A) Both are Binary B) Both are Decimal C) X is Binary and Y is Decimal D) Y is Binary and X is Decimal 2 10
X is binary and Y is Decimal.
43
What colour would rgb(255, 255, 0) or #FFFF00 most likely look like? A) Red B) Green C) Blue D) Yellow E) Purple / Violet
Yellow
44
RGB such as rgb(79, 38, 131) or #4F2683 is a representation used for A)Text B) Numbers C) Memory Addresses D) Colour
Colour
45
Operating Systems (OS): The programs run by an operating system which performs a service or function. Application Programs: A program that controls the computer’s resources. A) True B) False
False
46
Which one of the following is NOT an operating system? A) iOS B) Linux C) Android D) Firefox E) Unix
Firefox
47
True or False. Firmware is a special software on read-only memory (ROM) and Facebook is an example of such software
False
48
True or False. Objects are assigned to memory
True
49
What will this method do? slice = temp[:6]
Will print out every value from from the first element not includes the 6th element
50
What will this method do? slice = temp[6:]
Will print out the rest of the list but including the 6 position
51
What will this function do sort()?
It will sort a list from smallest to greatest
52
What will this method do .insert()?
Depending on the position it will add an element in a desired place in the list
53
Each pixel on your screen is made up of three subpixels, one for each of the following colours: A. Cyan, Magenta, Yellow B. Orange, Green, Violet C. Red, Yellow, Blue D. Red, Green, Blue E. White, Black, Green
Red, Green, Blue
54
CPU" stands for __________. A. Cache memory Processing User B. Computer Python Utility C. Computer Program Unit D. Central Printing Utility E. Central Processing Unit
Central Processing Unit
55
One of the main functions of a GPU is to: A. act as large-scale permanent file storage. B. act as short time volatile file storage. C. accelerate the rendering of 3D graphics. D. compile or interpret Python computer code written by the user. E. ensure the security of the computer’s network connection and encrypt Wifi traffic
Accelerate the rendering of 3D graphics
56
A byte can store ____ character(s) of text. A. 1 B. 4 C. 8 D. 5 E. 3
8 bytes
57
Which of the following is a volatile memory? A. Hard Disk Drive (HDD) B. Solid State Drive (SSD) C. Random Access Memory (RAM) D. Punch Card E. Blu-ray Disk
RAM is volatile.
58
Which mode in Python's open() function is used to both read and write to a file without replacing it?
"a"
59
Why is self used as the first parameter in class methods?
It is automatically assigned to the instance calling the method
60
What does isinstance() mean?
Returns True if the specified object is the specified object
61
Unit testing means...
Testing a class in isolation from other programs
62
Who developed Python? What year?
1990 and Gudio Van Rossum
63
Object Oriented Programming...
is a programming style which tasks are solved by collaborating items. Example, String, Lists, and File objects
64
What is public interface?
The set of all methods provided by a class together with a description of their behavior
65
Encapsulating means..
The process of providing a public interface while hiding the implementation details
66
What is the _ used for?
It is used to indicate to class users that should not directly access the instance variables
67
What is the difference between a function and a method?
A method a parameter that starts with self and it is found under a class. A function is not under a class and you do not need to use self.
68
What is the state of the object?
The values stored in an instance variable make up the state of the object
69
True or false. Always call a Python method with a double underscore ___
False
70
What is an accessor method?
An accessor method asks objects for info without changing it and normally returns current values
71
A mutator method...
Changes value and objects and usually takes a parameter that with change an instance variable. Ex. addItem()
72
What is a tester program?
A tester program is a driver module and contains statements to run methods in the class.
73
Object Reference means...
When a variable does not actually hold an object, but holds a memory location of an object
74
Shared Reference means...
Multiple object variables may contain reference to the same object. These are called aliases
75
How do you test if objects are aliases?
You use the is or is not operator.
76
___eq__ is used for ...
IS called to compare if 2 objects are equal
77
__str__ is used for...
returns a human readable or an informal string representation
78
__repr__ returns...
a more information rich or formal string
79
What does the type() function do?
Returns the type of the object
80
variable scope
the portion of code where a variable can be access or modified.