Basic Expressions (Expressions and Variables)

Write the following calculations in the text editor.

  1. 2 - 10
  2. 3 * 5
  3. 9 / 2
  4. 5 - 3 * 2
  5. (5 - 3) * 2
  6. 4 ^ 2
  7. 8 / 2 ^ 2

Run them by either clicking the Run button in the top-right corner of the editor or press Ctrl+Enter (Windows & Linux) or Command+Enter (Mac) to run code and print the results in the console.

If no code is highlighted/selected this will run the line the cursor is on. If you highlighted/selected a block of code it will run that entire group of lines.

You can also run the entire script by clicking the arrow next to Source and selecting Source with Echo or by using Ctrl+Shift+Enter (Windows & Linux) or Command+Shift+Enter (Mac).

To tell someone reading the code what this section of the code is about, add a comment line that says ‘Exercise 1’ before the code that answers the exercise. Comments in R are added by adding the # sign. Anything after a # sign on the same line is ignored when the program is run. So, the start of your program should look something like:

# Exercise 1

#1.1
2 - 10

#1.2
3 * 5
Expected outputs for Basic Expressions: 1