CSSE1001 Flashcards
What is the difference between syntax and semantics?
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)
What is Negation and Affirmation?
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.
Is the following a valid python expression?
>>> 3
Yes, as it is syntactically correct and python is able to read it as opposed to the following
>>> 3- Syntax error
True or false?
If x
and y
are valid Python expression then x + y
and x - y
are valid Python expression.
True. Any (syntactically correct) arithmetic expression can be added or subtracted from/to another (syntactically correct) arithmetic expressions
What is the highest order of operation?
Parenthesis
What comes after parenthesis in the order of operations?
Exponents
What operator functions as integer division
//
What is integer division
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.
What operator finds the remainder of an equation?
What is a remainder?
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.
True or false?
All operations with the same precedence (level of order in operations), are read from left to right.
False. It is true for all except exponentiation with is read from right to left.
Using knowledge of order of operations, what will be the output of the following:
>>> 3 * 1 // 2
>>> 3 * 1 // 2 1
The answer is 1
What does the following output?
>>> 3//2
>>> 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.
What does the following output?
>>> 17 // 3
>>> 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.
What does the following output?
>>> 2 ** 1 ** 0
>>> 2 ** 1 ** 0 2
In other words, it may be written as
>>> 2 ** (1 ** 0)
What does the following output?
>>> 3 * (1 // 2)
>>> 3 * (1 // 2) 0
True or false?
Using the divide operator (/) will cause the expression to turn into a float.
True.
As opposed to the following outputting an integer:
>>>3*4 12The following will output a float
>>> (3*4)/2 6.0
What does the following arithmetic expression evaluate to in Python?
>>> 2 ** 3 % 5 - 1
>>> 2 ** 3 % 5 - 1 2
What value gets assigned to x?
>>> x = 35 * 2 % 5 ** 2
>>> x = 35 * 2 % 5 ** 2 >>> x 20
What are the three primative control structures?
Sequencing
Conditioning
Looping
True or false?
While loops are used for infinite loops
False. Possibly infinite
Once the loop finishes, what gets assigned to x.
10
What keyword termintates a loop
break
What is the difference between while loop and do while loop?
do while will run atleast once and while loop runs from 0 times.