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
Q

What is the name of the constructor method in Python class?

A

__init__()

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

What is an instance variable in Python?

A

A variable defined inside a class to specific to each instance

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

In python, a function within a class definion is called a

A

method

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

Why is self used as the first parameter in class methods?

A

It is automatically assigned to the instance calling the method

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

True or False.
To divide 2 integers to get an integer result, you can use %%

A

False

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

What is a way to write counter = counter + 1?

A

counter += 1

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

What is the main purpose of the “break” function?

A

To terminate the loop and exit it prematurely

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

What does the term variable scope mean?

A

The portion of code where a variable can be accessed and modified.

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

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

A

c) 21

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

True or False.
The keys() method in Python returns the keys of a dictionary as list.

A

True

34
Q

True or False
Lists in Python can contain elements of different data types.

A

True

34
Q

What will this method do?
print(my_dct[:-2])

A

It will print out all the elemets except the last 2

35
Q

True or False.
Dictionaries are always of a fixed sixed and cannot be changed.

A

False

35
Q

True or False.
In Python dictionaries, keys must be unique, but values can be duplicated.

A

True

35
Q

What does this method do?
print(prices[1][2])?

A

It will access the dictionary full of lists. Then it will access the first list and then acess the second element.

36
Q

What will this line do?
return None

A

None

37
Q

Power supply, motherboard and CPU are examples of:
A) Inputs and Outputs
B) Internal Components
C) Memory
D) Storage
E) None of the above

A

Internal components

38
Q

The speed of the CPU is measured in:
A) Byte
B) Bit
C) Hz (Hertz)
D) None of the above

A

Hetz(Hz)

39
Q

True or False.
Hard Disk (HDD) and solid state drive (SSD) are
examples of non-volatile storage

A

True

40
Q

Which of the following is NOT an example of cloud
storage.
A) DropBox
B) iCloud
C) Solid State Drive
D) Google Drive

A

Solid State Drive

41
Q

In computers, data is represented using
A) 0 , 1
B) 10 , 2
C) 0, 1, 10
D) 0, 1, 10, 2

A

0, 1

42
Q

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

A

X is binary and Y is Decimal.

43
Q

What colour would rgb(255, 255, 0) or #FFFF00 most
likely look like?
A) Red
B) Green
C) Blue
D) Yellow
E) Purple / Violet

A

Yellow

44
Q

RGB such as rgb(79, 38, 131) or #4F2683 is a
representation used for
A)Text
B) Numbers
C) Memory Addresses
D) Colour

A

Colour

45
Q

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

A

False

46
Q

Which one of the following is NOT an operating system?
A) iOS
B) Linux
C) Android
D) Firefox
E) Unix

A

Firefox

47
Q

True or False.
Firmware is a special software on read-only memory
(ROM) and Facebook is an example of such software

A

False

48
Q

True or False.
Objects are assigned to memory

A

True

49
Q

What will this method do?
slice = temp[:6]

A

Will print out every value from from the first element not includes the 6th element

50
Q

What will this method do?
slice = temp[6:]

A

Will print out the rest of the list but including the 6 position

51
Q

What will this function do sort()?

A

It will sort a list from smallest to greatest

52
Q

What will this method do .insert()?

A

Depending on the position it will add an element in a desired place in the list

53
Q

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

A

Red, Green, Blue

54
Q

CPU” stands for __________.
A. Cache memory Processing User
B. Computer Python Utility
C. Computer Program Unit
D. Central Printing Utility
E. Central Processing Unit

A

Central Processing Unit

55
Q

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

A

Accelerate the rendering of 3D graphics

56
Q

A byte can store ____ character(s) of text.
A. 1
B. 4
C. 8
D. 5
E. 3

A

8 bytes

57
Q

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

A

RAM is volatile.

58
Q

Which mode in Python’s open() function is used to both read and write to a file without replacing it?

A

“a”

59
Q

Why is self used as the first parameter in class methods?

A

It is automatically assigned to the instance calling the method

60
Q

What does isinstance() mean?

A

Returns True if the specified object is the specified object

61
Q

Unit testing means…

A

Testing a class in isolation from other programs

62
Q

Who developed Python? What year?

A

1990 and Gudio Van Rossum

63
Q

Object Oriented Programming…

A

is a programming style which tasks are solved by collaborating items. Example, String, Lists, and File objects

64
Q

What is public interface?

A

The set of all methods provided by a class together with a description of their behavior

65
Q

Encapsulating means..

A

The process of providing a public interface while hiding the implementation details

66
Q

What is the _ used for?

A

It is used to indicate to class users that should not directly access the instance variables

67
Q

What is the difference between a function and a method?

A

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
Q

What is the state of the object?

A

The values stored in an instance variable make up the state of the object

69
Q

True or false.
Always call a Python method with a double underscore ___

A

False

70
Q

What is an accessor method?

A

An accessor method asks objects for info without changing it and normally returns current values

71
Q

A mutator method…

A

Changes value and objects and usually takes a parameter that with change an instance variable. Ex. addItem()

72
Q

What is a tester program?

A

A tester program is a driver module and contains statements to run methods in the class.

73
Q

Object Reference means…

A

When a variable does not actually hold an object, but holds a memory location of an object

74
Q

Shared Reference means…

A

Multiple object variables may contain reference to the same object. These are called aliases

75
Q

How do you test if objects are aliases?

A

You use the is or is not operator.

76
Q

___eq__ is used for …

A

IS called to compare if 2 objects are equal

77
Q

__str__ is used for…

A

returns a human readable or an informal string representation

78
Q

__repr__ returns…

A

a more information rich or formal string

79
Q

What does the type() function do?

A

Returns the type of the object

80
Q

variable scope

A

the portion of code where a variable can be access or modified.