Menu

[Solved]-Python Program Write Boolean Function Called Isfloat Analyze Given String Determine Repres Q37200764

Python Program

Write a Boolean function called is_float that will analyze agiven string to determine if it represents a valid floating-pointvalue, and return True if it does, or False if it does not.Remember, the number may be positive or negative, and may or maynot have a decimal component (integers are a subset of floats).

Examples:

>>> is_float(“hello”) False>>> is_float(“25”) True>>> is_float(“-13.4”) True>>> is_float(“-13-4”) False>>> is_float(“.13.4”) False>>> is_float(“3&%.@5”) False

Here is the IPO specification:

# is_float# Input: a string that may represent a floating-point number# Processing: check if the string could be converted to a float value# without error, by analyzing the characters in the string.# Output: (bool) True if the string represents a valid float, else False

Note: You have learned a few different toolswith which to do this. It doesn’t require a lot of lines of code.Just make sure your function accepts all possible valid floats, andrejects anything that cannot be a float. For example: “3.2.4”,”-75-“, “a345” should all return False.

Now, using your function, write a simple program that asks fortwo floating point numbers and multiplies them.

For example:

Enter a floating-point number: HelloThat isn’t a number.Enter a floating-point number: 30.02.10That isn’t a number.Enter a floating-point number: 3.14Great.Enter another floating-point number: 2Great.3.14 * 2.0 = 6.28

Expert Answer


Answer to Python Program Write a Boolean function called is_float that will analyze a given string to determine if it represents a… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *