Type Explorer
Python distinguishes between integers (`int`) and floating-point numbers (`float`). Division `/` always results in a `float`, while floor division `//` results in an `int` (if operands are ints). Functions `int()` and `float()` can convert types. Predict the output of the code below.
Exponent & Modulo Challenge
Recall that `**` is exponentiation (power) and `%` is modulo (remainder). Predict the output of this calculation, paying attention to operator precedence (`**` is higher than `*`, `/`, `%`, `//`, which are higher than `+`, `-`).
Intro to `math` Module
Python has a built-in `math` module for more advanced operations. You typically need to `import math` first, but for this simulation, assume it's available. Try using `math.sqrt()` for square root or `math.ceil()` to round up.
math.sqrt(x)
finds the square root of x, math.ceil(x)
rounds x up to the nearest integer, math.floor(x)
rounds x down.
Advanced Mini Missions!
Combine your skills! Solve these problems using arithmetic operators, type conversions, or math functions as needed. Check your results with the simulator.
Mission 1: Pythagorean Theorem
A right-angled triangle has sides `a = 7` and `b = 11`. Calculate the length of the hypotenuse `c` using the formula c = sqrt(a² + b²). Use `math.sqrt()` and `**` for exponentiation. Print the result.
Mission 2: Celsius to Fahrenheit
Convert `25` degrees Celsius to Fahrenheit using the formula: F = (C * 9/5) + 32. Print the result. Ensure the division results in a float for accuracy.
Module 2 Advanced Practice Complete!
Excellent work exploring number types, advanced operators, and the `math` module! You're building a strong foundation.
Consider reviewing the Practice exercises or watching the Video Lesson for reinforcement.