Python operators obey normal mathematical rules such as PEMDAS.
Expressions are evaluated left to right in your source code
This table on the right is very helpful when navigating through operations. The symbol shows what will be used to compute the described operation. The syntax shows what it might look like in python.
Example of using an operators:
In the code box below, show how you would print the following mathematical operations:
a. subtracting 4 from 8
b. multiplying 10 and 3
c. dividing 16 by 2
d. raising 8 to the power of 2
Hint: use the examples in the video to guide you
Using string concatenation, print these two strings on a single line!
1. Your job is to set a variable equal to 10/3, then print it in the following ways:
a. With 8 spaces to the right, rounded to 3 decimal places.
b. Printing "The number is: " before you print the variable (must be on the same line).
c. Print the variable times 1,000 with commas.
Note: in the example above, you see a special character \n. This is basically the same as hitting the Enter button on your keyboard. It makes a new line on a print statement!
We are going to write a program that calculates how many weeks old you are based on how many years old you are. Then, it will print your age in weeks and years!
1. To do this, follow the commented "TODO" statements below. They should help guide you.
The output should look like this: