June 2024
Beginner to intermediate
908 pages
15h 59m
English
Write a Python program that prompts the user to enter a number and then displays a message indicating whether the data type of this number is integer or real.
Solution
It is well known that a number is considered an integer when it contains no fractional part. In Python, you can use the int() function to get the integer portion of any real number. If the user-provided number is equal to its integer portion, then the number is considered an integer.
For example, if the user enters the number 7, this number and its integer portion, int(7), are equal.
On the other hand, if the user enters the number 7.3, this ...
Read now
Unlock full access