1.14. Exercises#
For each of the following expressions, what value will the expression produce? Verify your answers by typing the expressions into Python.
9 - 38 * 2.59 / 29 / -29 // -29 % 29.0 % 29 % 2.09 % -2-9 % 29 / -2.04 + 3 * 5(4 + 3) * 5
Unary minus negates a number. Unary plus exists as well; for example, Python understands
+5. Ifxhas the value-17, what do you think+xshould do?Should it leave the sign of the number alone?
Should it act like absolute value, removing any negation? Use the Python shell to find out its behavior.
Write two assignment statements that do the following:
Create a new variable,
temp, and assign it the value24.Convert the value in
tempfrom Celsius to Fahrenheit by multiplying by1.8and adding32. Maketemprefer to the resulting value. What istemp’s new value?
For each of the following expressions, in which order are the subexpressions evaluated?
6 * 3 + 7 * 45 + 3 / 45 - 2 * 3 ** 4
Exercise
Create a new variable
x, and assign it the value10.5.Create a new variable
y, and assign it the value4.Sum
xandy, and makexrefer to the resulting value. After this statement has been executed, what are the values ofxandy?
When a variable is used before it has been assigned a value, a
NameErroroccurs. In the Python shell, write an expression that results in aNameError.Which of the following expressions result in
SyntaxErrors?6 * ———--88 = people((((4 ** 3))))(-(-(-(-5))))4 += 7 / 2