Exercises In this section we will do some basic programming exercises to test your understanding of the lecture material and to let you experiment with WingIDE and the Python shell. We will also introduce you to a few features of Python that we didn't talk about in the lectures. For each of the following expressions, what value will the expression give? Verify your answers by typing the expressions into the Python shell. 9 - 3 8 * 2.5 9 / 2 9 / -2 9 % 2 9 % -2 -9 % 2 9/ -2.0 4 + 3 * 5 (4 + 3) * 5 2) Python includes a lot of operators of the form where is one of the standard op=, op operators. For instance, the following are all operators: += -= *= /= %=. The meaning of these operators is as follows: x op= y is the same as x = x op y For instance, is the same as and is the same as x += y x = x + y y -= 2 y = y - 2. For each of the following statements, what will be the value of the variable after the statement x has been executed? Assume that the statements are entered into the Python shell one after another, so that subsequent statements can depend on the values of previous ones. x = 100 x = x + 10 x += 20 x = x - 40 x -= 50 x *= 3 x /= 5 x %= 3 3)Write a step-by-step description of what happens when Python evaluates the statement x += when has the initial value of What is after the statement has been evaluated? x - x x 3. x 4) Complex numbers are the sum of a real number and an imaginary number. An imaginary number is just a real number multiplied by the square root of The square root of is often -1. -1 called or Python allows you to enter complex numbers directly, in the form (for i j. Yj imaginary numbers) and X+Yj (for complex numbers). What are the values of the following expressions?
Exercises In this section we will do some basic programming exercises to test your understanding of the lecture material and to let you experiment with WingIDE and the Python shell. We will also introduce you to a few features of Python that we didn't talk about in the lectures. For each of the following expressions, what value will the expression give? Verify your answers by typing the expressions into the Python shell. 9 - 3 8 * 2.5 9 / 2 9 / -2 9 % 2 9 % -2 -9 % 2 9/ -2.0 4 + 3 * 5 (4 + 3) * 5 2) Python includes a lot of operators of the form op=, where op is one of the standard operators. For instance, the following are all operators: += -= *= /= %=. The meaning of these operators is as follows: x op= y is the same as x = x op y For instance, x += y is the same as x = x + y and y -= 2 is the same as y = y - 2. For each of the following statements, what will be the value of the variable x after the statement has been executed? Assume that the statements are entered into the Python shell one after another, so that subsequent statements can depend on the values of previous ones. x = 100 x = x + 10 x += 20 x = x - 40 x -= 50 x *= 3 x /= 5 x %= 3 3)Write a step-by-step description of what happens when Python evaluates the statement x += x - x when x has the initial value of 3. What is x after the statement has been evaluated? 4) Complex numbers are the sum of a real number and an imaginary number. An imaginary number is just a real number multiplied by the square root of -1. The square root of -1 is often called i or j. Python allows you to enter complex numbers directly, in the form Yj (for imaginary numbers) and X+Yj (for complex numbers). What are the values of the following expressions?
supplementary_exercises.docx