Python 2
Know all of the mathematical operators and how they are used.
-x, x+y, x-y, x*y, x/y, x//y, x%y, x**y
The default character encoding scheme of Python is ________
UTF-8
Give the following values in the exponential notation of Python, such that there is only one significant digit to the left of the decimal point. (a) 4580.5034 (b) 0.00000046004 (c) 5000402.000000000006
a) format(4589.5034, '.1e')= 4.6e+03 b) format(0.00000046004, '.1e')= 4.6e-07 c) format(5000402.000000000006, '.1e')= 5.0e+06
Regarding variable assignment, (a) What is the value of variables num1 and num2 after the following instructions are executed? num = 0 k = 5 num1 = num + k * 2 num2 = num + k * 2 (b) Are the values id(num1) and id(num2) equal after the last statement is executed?
a)10? b)yes
Regarding the built-in format function in Python, (a) Use the format function to display the floating-point value in variable result with three decimal digits of precision. (b) Give a modified version of the format function in (a) so that commas are included in the displayed results.
a)format(result, '.3f') b)format(result, ',.3f')
Regarding input function in Python, (a) Give an instruction that prompts a user for their last name and stores it in a variable named last_name. (b) Give an instruction that prompts a user for their age and stores it as an integer in a variable named age. (c) Give an instruction that prompts a user for their temperature and stores it as a float in a variable named current_temperature.
a)last_name=input('What is your last name?') b)age=int(input("What is your age?")) c)current_temperature=float(input("What is your temperature?"))
A calculated result too small to be represented is referred to as ____________
arithmetic underflow
Which of the floating-point values in question 2 would exceed the representation of the precision of floating points typically supported in Python, as mentioned in the chapter?
c
Match the values with their respective data types (a) 12 __ String (b) 12.45 __ Integer (c) 'Hello' __ Float
c String a Integer b Float
What is displayed by the following? print(format( '-', '->8 '), 'Hello ') a) Hello --- b) --- Hello c) -------- Hello
c) -------- Hello
The built-in _________________ function of Python can be used to control the display of both numeric and string values
format
A numeric literal may be an __________ or _________________ value
integer floating point
Truncating division performed on integer operands is referred to as ___________
integer division
Give a call to print that is provided one string that displays the following address on three separate lines. John Doe 123 Main Street Anytown, Maryland 21009
print('John Doe\n123 Main Street\nAnytown, Maryland 21009')
Numeric literals consist of only the digits 0-9, and optional ________ and ____________
sign character possible decimal point
Parenthesize all of the subexpressions in the following expressions following operator precedence in Python. (a) var1 * 8 - var2 + 32 / var3 (b) var1 - 6 ** 4 * var2 ** 3
(a) (var1 * 8) - var2 + (32 / var3 ) (b) var1 - ((6 ** 4) * (var2 ** 3 )
What is the exact result of each of the following when evaluated? (a) 12 / 6.0 (b) 21 // 10 (c) 25 // 10.0
(a) 12 / 6.0 =2.0 (b) 21 // 10 =2 (c) 25 // 10.0 =2.0
The expression 4 + 3 is in (a) prefix Notation (b) infix Notation (c) postfix Notation
(b) infix Notation
Which of the following arithmetic expressions could potentially result in arithmetic overflow, where n,k are each assigned integer values, and q,r are each assigned floating-point values? (a) n * k (b) n ** k (c) n * q (d) r * q
(b) n ** k
Indicate what is displayed by the following. tax = .08 print('Your cost: $', format((1 + tax) * 12.99, '.2f''))
Your cost: $ 14.03