Lesson 1 (Operations)
A computer is, at heart, a very complex calculator. We can use the computer to perform calculations using the +, -, *, and / operators to add, subtract, multiply, and divide, respectively. Parentheses () also work the same way as in the order of operations; anything in parentheses is performed before other operations.
Using Repl.it: press the “run” button at the top of the embedded code terminal. This will cause anything in the white text box to be executed below, in the black section. So if you write a mathematical calculation in the white text box (such as print(4 +5)), the answer to it (the output) will be displayed in the black section after you press “run.” In many of these exercises, the code has been written out for you, and all you need to do is press “run.” Later, there will be exercises where we ask you to write code yourself — in those cases, write out the code in the white box and then press “run.”
Comments are lines of code that are ignored by the computer, but are useful to coders to write notes to themselves or others reading their code. A comment is created with the # sign (#CommentYourCode will be trending any day now). Notice how in the following example, when an operation is preceded by a #, no output prints for that line.
Now it's your turn!
Click on the Edit in Repl.it button in the upper right corner of the terminal below. This will take you to the repl.it website, where you can create a free account (recommended, if you haven't already). Then, you can write, run, and save your own code to answer the questions below (also provided as comments on the repl.it site). Alternatively, just type in the box below and run as normal to check your answers!
- Add 6.3 to 8.2
- Multiply 45.5 by 3.4
- Convert 75 degrees Fahrenheit to Celsius. To calculate this, multiply the difference between the temperature in Fahrenheit and 32 by 0.556. Hint: the formula is TempCelsius = (TempFahrenheit - 32) * 0.556
If you have any trouble navigating the repl.it site, please see our Student Guide to Repl.it.