Question: Hi, I wrote the code below, but, I am getting the below error. The call iseurofloat( '12,5' ) returns 2 , not True. My code

Hi,

I wrote the code below, but, I am getting the below error.

The call iseurofloat('12,5') returns 2, not True. 

My code is below.

try:

result = introcs.index_str(s,',')

d1 = s[:result]

d2 = s[result+1:]

int(d1)

int(d1+d2)

return result

except:

return result

The complete function is below.

"""

A function to test for floats in European format

Author:

Date:

"""

import introcs

def iseurofloat(s):

"""

Returns True if s is a float in European format.Returns False otherwise.

In European format, a comma is used in place of a decimal point.So '12,5' stands

for 12.5, '0,12' stands for 0.12 and so.Formally, a string is in European format

if it is of the form , where d1 and d2 are ints (and d2 >= 0).See

https://en.wikipedia.org/wiki/Decimal_separator

for more information.

This function does not recognize floats in scientific notation (e.g. '1e-2').

Examples:

iseurofloat('12,5') returns True

iseurofloat('-12,5') returns True

iseurofloat('12') returns False

iseurofloat('12,-5') returns False

iseurofloat(',5') returns False

iseurofloat('apple') returns False

iseurofloat('12,5.3') returns False

iseurofloat('12,5,3') returns False

iseurofloat('1e-2') returns False

Parameter s: The string to check

Precondition: s is a string

"""

# You MAY NOT use conditionals anywhere in this function.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!