Lesson guide
What this Python exercise practices
Convert Float to Integer is a intermediate practice lesson that focuses on functions, parameters, return values. It is designed to be solved in about 15 minutes with examples, starter code, and test feedback.
Prerequisites
- Python variables
- Function parameters
- Return values
Difficulty and time
- Level
- Intermediate
- Estimated time
- 15 minutes
Practice path
Summary
Convert a floating-point number to an integer by truncating the fractional part.
Problem statement
Given a single floating-point number, return its integer conversion using Python's default behavior: drop the fractional part (truncate toward zero). Do not round — simply convert to int. For example, 3.9 becomes 3, -2.7 becomes -2, and 0.0 becomes 0.
Task
Write a function that converts a float to an integer using Python's truncation behavior (toward zero).
Examples
Positive float
Input
convert_float_to_int(3.9)
Output
3
Explanation
The fractional part .9 is dropped, producing 3.
Input format
A single floating-point number is passed as the only argument to the function convert_float_to_int.
Output format
Return an integer that is the result of converting the input float to int.
Constraints
- Use Python's int conversion semantics (truncate toward zero). - Input will be a finite float (no need to handle NaN or infinity for this exercise).
Samples
Sample input 0
convert_float_to_int(-2.7)
Sample output 0
-2
Explanation 0
Negative floats truncate toward zero, so -2.7 -> -2.
AI assistant
Ask me anything!
Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.
Chat history is temporary and will not be saved.
Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.