CSSE1001 Flashcards

1
Q

What is the difference between syntax and semantics?

A

Syntax is what it means for the code to be grammatically correct while semantics is what the code actually does.

For example, the sentence “Colourless green ideas sleep furiously” is correct grammatically (syntax) but doesn’t make sense (semantic)

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

What is Negation and Affirmation?

A

Negation is when a number is turned into a negative (multiplied by -1) while Affirmation is when a number is turned into a positive (multiplied by +1).

For example, -x is negation while +x is affirmation.

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

Is the following a valid python expression?

>>> 3
A

Yes, as it is syntactically correct and python is able to read it as opposed to the following

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

True or false?

If x and y are valid Python expression then x + y and x - y are valid Python expression.

A

True. Any (syntactically correct) arithmetic expression can be added or subtracted from/to another (syntactically correct) arithmetic expressions

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

What is the highest order of operation?

A

Parenthesis

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

What comes after parenthesis in the order of operations?

A

Exponents

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

What operator functions as integer division

A

//

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

What is integer division

A

Integer division refers to the process of dividing two integers and obtaining the quotient without any fractional part.

For example, in integer division, 7 ÷ 2 = 3 where 3 is the quotient while there is also a remainder of 1.

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

What operator finds the remainder of an equation?

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

What is a remainder?

A

If a number cannot be evenly divided by another number, the number left over at the end of the division is called the remainder.

For example, in integer division, 7 ÷ 2 = 3 where 3 is the quotient while there is also a remainder of 1.

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

True or false?

All operations with the same precedence (level of order in operations), are read from left to right.

A

False. It is true for all except exponentiation with is read from right to left.

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

Using knowledge of order of operations, what will be the output of the following:

>>> 3 * 1 // 2
A
>>> 3 * 1 // 2
1

The answer is 1

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

What does the following output?

>>> 3//2
A
>>> 3//2
1

// is integer division. In the expression, 3//2, we basically ask how many 2’s will fit into 3 which is only 1.

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

What does the following output?

>>> 17 // 3
A
>>> 17 // 3
5

// is integer division. In the expression, 17//3, we basically ask how many 3’s will fit into 17 which is 5.

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

What does the following output?

>>> 2 ** 1 ** 0
A
>>> 2 ** 1 ** 0
2

In other words, it may be written as

>>> 2 ** (1 ** 0)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does the following output?

>>> 3 * (1 // 2)
A
>>> 3 * (1 // 2)
0
17
Q

True or false?

Using the divide operator (/) will cause the expression to turn into a float.

A

True.

As opposed to the following outputting an integer:

>>>3*4
12
The following will output a float
>>> (3*4)/2
 6.0
18
Q

What does the following arithmetic expression evaluate to in Python?

>>> 2 ** 3 % 5 - 1
A
>>> 2 ** 3 % 5 - 1
2
19
Q

What value gets assigned to x?

>>> x = 35 * 2 % 5 ** 2
A
>>> x = 35 * 2 % 5 ** 2
>>> x
20
20
Q

What are the three primative control structures?

A

Sequencing
Conditioning
Looping

21
Q

True or false?

While loops are used for infinite loops

A

False. Possibly infinite

22
Q

Once the loop finishes, what gets assigned to x.

23
Q

What keyword termintates a loop

24
Q

What is the difference between while loop and do while loop?

A

do while will run atleast once and while loop runs from 0 times.

25
How can you define lists
Mutable Ordered Collections
26
What is it meant to be mutable
Can be changed (lists and dictionaries)
27
Are strings mutable
no
28
What prints in the following (REPL)
True.
29
What prints in the following (REPL)
False. The list, [1] is not in the list
30
What is the difference of function and method
Methods usually change what is dotted with it (xs.append(3))
31
What prints in the following REPL
32
True or false? Mutable types store references, not the actual value
True. Assigning something to a mutable type will assign it to the reference. But with a immutable type it essentially "copies" the value
33
What prints in the following REPL
34
What is the difference between the line 3 and: ```>>> ys=xs```
ys=xs will assign ys to xs reference point. But copy will actually copy the values of xs and assign it to ys
35
What is the main difference between tuples and lists
Lists are mutable and tuples are immutable
36
What is the difference between line 6 and line 9
6 appends and changes the list. 9 concatenates and creates a whole new list
37
What is the difference between line 8 and line 10
10 will not give an error
38