I'm trying to convert a string list into floats but this can't be done with a number like 1,234.56. Is there a way to use the string.replace() function to remove the comma so i just have 1234.56? string.replace(',','') doesn't seem to work. This is my current code:
fileName = (input("Enter the name of a file to count: "))
print()
infile = open(fileName, "r")
line = infile.read()
split = line.split()
for word in split:
if word >= ".0":
if word <= "9":
add = (word.split())
for num in add:
x = float(num)
print(x)
This is my error I'm getting:
File "countFile.py", line 29, in main x = float(num) ValueError: could not convert string to float: '3,236.789'