Simple Assignments

  1. Write code to create a variable score and make it refer to the integer 1.
    Remember that an assignment is a = with a variable on the left-hand side and a value or expression on the right-hand side.
  1. Write code to create a variable temperature and make it refer to a floating point number.
    A floating point number is a real number. I.e., it has a . in it.
  1. Write code to create a variable name and make it refer to a string.
    A string is enclosed by single or double quotes.
  1. Write code to create a variable matches and make it refer to a boolean value.
    The two booleans values are True and False.
  1. Assume the variable temperature has been initialized to some value. Write code to add 1 to the variable temperature.
    The right-hand side of an equation is evaluated first, so you can take temperature and add 1 to it on the right-hand side, and then put temperature on the left-hand side of the = sign.
  1. Assume you have two variables hours and hourly_rate. Write code to compute the total_pay, by multiplying hours and hourly_rate and storing in total_pay.
    Multiply hours and hourly_rate on the right-hand side of the assignment statement.
  1. Assume you have two variables p1_points and p2_points. Write a line of code to indicate that player p1 added all of player p2’s points to her own.
    Your code needs to add p2_points to p1_points and make p1_points refer to the result.
  1. Assume you have a variable ball1_direction. Write a line of code that set ball2’s direction to be the same as ball1’s direction.
    Your code creates variable ball2_direction on the left-hand side of the = sign and sets it value to ball1_direction.
  1. Replace these statements with a single statement so that you don’t use the variable y – just the variable x being set to a value.

  1. Before running the following code, predict what value will be printed.

    If you don’t understand the answer, using CodeLens might help.

Next Section - Input and Output