python - Solve the error : could not convert string to float: '0.1222000000*10e1' -
expo2 = ['0.1222000000*10e1', '0.9310000000*10e-1', '0.2580000000*10e1', '0.2580000000*10e1', '0.2580000000*10e1', '0.8850000000*10e-1', '0.8850000000*10e-1', '0.8850000000*10e-1', '0.8850000000*10e0', '0.8850000000*10e0', '0.8850000000*10e0', '0.8850000000*10e0', '0.8850000000*10e0', '0.1222000000*10e1', '0.9310000000*10e-1', '0.2580000000*10e1', '0.2580000000*10e1', '0.2580000000*10e1', '0.8850000000*10e-1', '0.8850000000*10e-1', '0.8850000000*10e-1', '0.8850000000*10e0', '0.8850000000*10e0', '0.8850000000*10e0', '0.8850000000*10e0', '0.8850000000*10e0']
i have list of numbers. use them, tried use float commands but, when wrote:
print(float(expo2[0]))
i got error message:
valueerror: not convert string float: '0.1222000000*10e1'
how can convert numbers floats?
i think correct formula:
expo2 = ['0.1222000000*10e1', '0.9310000000*10e-1', '0.2580000000*10e1', '0.2580000000*10e1', '0.2580000000*10e1', '0.8850000000*10e-1', '0.8850000000*10e-1', '0.8850000000*10e-1', '0.8850000000*10e0', '0.8850000000*10e0', '0.8850000000*10e0', '0.8850000000*10e0', '0.8850000000*10e0', '0.1222000000*10e1', '0.9310000000*10e-1', '0.2580000000*10e1', '0.2580000000*10e1', '0.2580000000*10e1', '0.8850000000*10e-1', '0.8850000000*10e-1', '0.8850000000*10e-1', '0.8850000000*10e0', '0.8850000000*10e0', '0.8850000000*10e0', '0.8850000000*10e0', '0.8850000000*10e0'] floats = [] f in expo2: try: a, e = f.split("*") floats.append(float(a) * float(e)) except valueerror e: print("not float") print(floats) [12.22, 0.931, 25.8, 25.8, 25.8, 0.885, 0.885, 0.885, 8.85, 8.85, 8.85, 8.85, 8.85, 12.22, 0.931, 25.8, 25.8, 25.8, 0.885, 0.885, 0.885, 8.85, 8.85, 8.85, 8.85, 8.85]
you can verify using eval:
print(all(a == eval(b) a,b in zip(floats, expo2))) true
10e-1
1 10e1
100:
in [25]: 10e-1 out[25]: 1.0 in [26]: 10e-2 out[26]: 0.1 in [27]: 10e-3 out[27]: 0.01 in [28]: 10e1 # 10 * 10^1 -> 10 * 10 out[28]: 100.0 in [29]: 10e2 # 10 * 10^2 -> 10 * 10 * 10 out[29]: 1000.0 in [30]: 10e3 # 10 * 10^3 -> 10 * 10 * 10 * 10 out[30]: 10000.0
a table this site using 1.0 coefficient:
1.0 coefficient 10 base n exponent 1.0*10e-24= 0.000,000,000,000,000,000,000,001 or yocto 1.0*10e-21= 0.000,000,000,000,000,000,001 or zepto 1.0*10e-18= 0.000,000,000,000,000,001 or 1 quintillionth, alto 1.0*10e-15= 0.000,000,000,000,001 or 1 quadrillionth, femto 1.0*10e-12= 0.000,000,000,001 or 1 trillionth, pico 1.0*10e-11= 0.000,000,000,01 1.0*10e-10= 0.000,000,000,1 1.0*10e-09= 0.000,000,001 or 1 billionth, nano 1.0*10e-08= 0.000,000,01 1.0*10e-07= 0.000,000,1 1.0*10e-06= 0.000,001 or 1 millionth, micro 1.0*10e-05= 0.000,01 1.0*10e-04= 0.000,1 1.0*10e-03= 0.001 or 1 thousandth, milli 1.0*10e-02= 0.01 or centi 1.0*10e-01= 0.1 or deci 1.0*10e00= 1 or units or (v,i,r,p,)(meter,liter,gram,)(seconds)ƒ(herz cycles) 1.0*10e01= 10 or deka 1.0*10e02= 100 or hecto 1.0*10e03= 1,000 or kilo 1.0*10e04= 10,000 or (10k) 1.0*10e05= 100,000 or (100k) 1.0*10e06= 1,000,000 or mega 1.0*10e07= 10,000,000 or (10m) 1.0*10e08= 100,000,000 or (100m) 1.0*10e09= 1,000,000,000 or giga 1.0*10e12= 100,000 000,000 or tera 1.0*10e15= 100,000,000,000,000 or peta 1.0*10e18= 100,000,000,000,000,000 or exa 1.0*10e21= 100,000,000,000,000,000,000 or zetta 1.0*10e24= 100,000,000,000,000,000,000,000 or yotta
if have mixture:
expo2 = ['0.1222000000*10e2', "1.0", "4r", "2.123e4", '0.9310000000*10e-1', '0.2580000000*10e1',"foo"] floats = [] f in expo2: try: a, e = f.split("*") floats.append(float(a) * float(e)) except valueerror: try: floats.append(float(f)) except valueerror e: print(e) not convert string float: '4r' not convert string float: 'foo' [122.2, 1.0, 21230.0, 0.931, 25.8]
Comments
Post a Comment