Fall 2024 - P5
Big Idea 3 | .1 | .2 | .3 | .4 | .5 | .6 | .7 | .8 | .10 |
3.3 Mathematical Operations
Learn the different types of Mathematical Operations
Popcorn Hack 1
- Create an algorithm that adds 2 set variables together, then it divides that number by 4, then prints that number in both python and javascript.
Python version
- The python code down below follows a specific order. First the computer will register num1 as 5 and num2 as 11. Then it will print num1 and then num2.
num1 = 5
num2 = 11
print(num1) # Output would be 5
print((num1 + num2) / 4) # output should be 4.0
Javascript version
- The Javascript code below does the exact same thing as the python example above.
let num1 = 5; let num2 = 11; console.log(num1) console.log((num1 + num2) / 4)
Popcorn Hack 2
- Create an algorithm that multiplies two values together and then takes the mod of those two values when divided.
Python Version:
numb1 = 12
numb2 = 8
product = numb1 * numb2
print("Product:", product) # Output should be Product: 96
modulus = product % numb2
print("Modulus:", modulus) # Output should be Modulus: 0
Javascript Version-Does the same as the python version above:
let numb1 = 12
let numb2 = 8
let product = numb1 * numb2
console.log("Product:", product)
let modulus = product % numb2
console.log("Modulus:", modulus)
Popcorn Hack 3
- Make a algorithm that subtracts 2 numbers.
Python version:
x=7
y=2
print(x - y) #Output should be 5
Javascript Version
let x=7;
let y=2;
console.log(x - y) // Output should be 5