I'm writing a script to return a number to a certain amount of significant figures. I need to turn a float into a list so that I can change the number easily. This is my code:
def sf(n,x):
try:
float(n)
isnumber = True
except ValueError:
isnumber = False
if isnumber == True:
n = float(n)
n = list(n)
print(n)
else:
print("The number you typed isn't a proper number.")
sf(4290,2)
This returns the error:
Traceback (most recent call last):
File "/Users/jacobgarby/PycharmProjects/untitled/py package/1.py", line 29, in <module>
sf(4290,2)
File "/Users/jacobgarby/PycharmProjects/untitled/py package/1.py", line 25, in sf
n = list(n)
TypeError: 'float' object is not iterable
What does this error mean, and how can I stop it from happening?