Back to Lessons
BeginnerBasics

Numbers and Math

lesson_12.py
>>> ## Concept In Python, you can work with different types of numbers: **integers** and **floats**. Integers are whole numbers without any decimals, like 1, 2, or 100. Floats, on the other hand, are numbers with decimal points, such as 3.14 or 2.5. You can perform arithmetic operations with these numbers just like in regular math. Here's an example: ```python # Example of integer and float whole_number = 10 decimal_number = 3.14 # Add both numbers result = whole_number + decimal_number print(result) # Output will be 13.14 ``` When you perform operations between an integer and a float, Python automatically converts the integer to a float to maintain precision. ## Practice For this exercise, you need to use both an integer and a float in your calculations: 1. **Create a variable** named `age` and set it to `12` (an integer). 2. **Create another variable** named `height` and set it to `4.5` (a float). 3. **Print** the sum of `age` and `height`. Here's a hint to get you started: ```python # Create age and height variables # Add them together and print the result ``` Make sure to use `print()` to display the sum, and it should result in an output of `16.5`.
Code Editor

Sign in to submit your answer and earn XP.