My use case is: I’m getting three values returned from three tkinter comboboxes, which can either be a string representing a number or a float, returned as a string array of arrays. ie [‘[10]’, ‘[20.0]’, ‘[1.0]’].
I then need to convert these three number/float representations so I can multiply these values together for a total number. However, because they are string arrays my is_float function doesn’t seem to do anything? I
If the best solution is to strip out the brackets I can do that, but I was wondering if there is another solution for this?
Here is the code so far:
def is_float(string):
try:
# Check if the string is a valid float
float_value = float(string)
print("Value is float!")
return True
except ValueError:
print("Value is not a float!")
return False
# ['[10]', '[20.0]', '[1.0]']
value_a = '[10]'
value_b = '[20.0]'
value_c = '[1.0]'
if is_float : value_a
else:
# I assume I need to make the string into a float type representation.
value_a = value_a + '.0'
print(value_a)
total = [float(value_a) * float(value_b) * float(value_c)]
print("The total is: ")
print(total)
Seems so simple, but I haven’t been able to get anything to work, nor does it pass anything to the function because it’s not a string in it’s current state. Any ideas?