The computer can also do your regular math that you do in school. Use print to print out the result from the math expressions. No quotation marks are needed for numbers! Unlike strings, you can do math on numbers.
The computer does division differently from your regular calculator. Computer division will exclude remainders or decimals.
3 and not
You can also try using the math symbols to make your own expressions!
Let’s try to figure out the answers to the following using Python. Try printing out the result of the below (make sure you don’t miss any parentheses):
- 2 - 19
- (3 + 5) * 6
- (13 + 5 * 8) / (6 - (3 + 7))
Can you print out this statement?
"527 time 199 is: __"
You will fill in the blank with the answer of what
(527 * 199) is. If you want to print a string and a number together, you first have to convert the number into a string.
Here’s an example: print(
"Hello, World!" + str(5))
str(5) turns the number into the string
"5". Converting one type of thing to another is called “casting”.
Fun Fact: Random Numbers
Here is how to print a random number between 1 (inclusive) and 10 (inclusive):
from random import randint
Want to know more? Ask for help or poke around on the internet! Every coder’s best friend is a search engine!
In particular, try understanding what the from and the import words mean. We will come back to these words later during the project.