I have a list storing variables. These variables store float numbers. For part of the program I am making, if a value has .0 at the end, I need to remove it and if not, it can stay the same.
For example: 2.0 would become 2 3.5 would stay as 3.5
Now the issue is later on in the program I need to sort and round the same set of numbers up and down. The question would be too long if I included all of the reasoning for as to why this is.
The code I have currently is as follows:
AddRatio=0.35
SubRatio=0.2
MultiRatio=0.2
DiviRatio=0.2
MoneyRatio=0.25
num_add_qs=10*AddRatio
num_sub_qs=10*SubRatio
num_multi_qs=10*MultiRatio
num_divi_qs=10*DiviRatio
num_money_qs=10*MoneyRatio
NumQs = [num_add_qs, num_sub_qs, num_multi_qs, num_divi_qs, num_money_qs]
for i in range(0,len(NumQs)):
if isinstance(NumQs[i], float) == True:
NumQs[i]=str(NumQs[i])
if NumQs[i][2]=="0":
NumQs[i]=NumQs[i][0:1]
NumQs[i]=int(NumQs[i])
else:
NumQs[i]=float(NumQs[i])
i=i+1
If I
print(NumQs)
it returns
[3.5, 2, 2, 2, 2.5]
which are the results I want.
The issue is the actual value of the variable isn't changed. If I:
print(num_add_qs, num_sub_qs, num_multi_qs, num_divi_qs, num_money_qs)
The result is:
3.5 2.0 2.0 2.0 2.5
The variables need to be stored as integers if whole integers and floats if not. I convert them to strings purely to remove the .0 if relevant.
Where am I going wrong?