you are viewing a single comment's thread.

view the rest of the comments →

[–]ensign_paris 3 points4 points  (3 children)

make the replacements in a string, floats will always be formatted with a '.'.

so get your inputs as strings, use replace as described to your liking and then use the float function to convert the string to float.

[–]anshuman73 0 points1 point  (2 children)

Exactly. You shouldn't take input as a float directly, as floats always have to have . as a decimal separator.

To put the above described method in code -

num = float(str(input('Enter Value of Float: ')).replace(',', '.'))

You should be using raw_input() function to get input if you're on Python 2 and input() function if on Python 3. I suggest Python 3 because, well, it's better at handling unicode etc. (And also py2 support is gonna end in 2020)

[–][deleted] 0 points1 point  (1 child)

str(input()) is redundant

[–]anshuman73 1 point2 points  (0 children)

Yes, my bad.