When I make the first parameter less than three decimal places and try make it be converted to three decimal places it won't do it. It will just add it to the list how I wrote it. If the value is 9.13, it won't print in the list as 9.130, it will still be 9.13. I've tried the round function, formatting, etc. Also, when an integer is added to the list it will only print to one decimal place. For example, 27 will only print 27.0 instead of 27.000.
import math
def generate_num(LowNum, HighNum):
try:
LowNum = float(LowNum)
HighNum = float(HighNum)
except ValueError:
return False
except KeyboardInterrupt:
quit()
LowNum = round(LowNum, 3)
sequence = [LowNum]
j = sequence[-1]
while j <= HighNum:
i = (math.sqrt((j) ** 3))
i = round(i, 3)
if i <= HighNum:
sequence.append(i)
j = i
else:
break
return sequence
print(generate_num(9, 923))
The function round() does not determine the format when a list is printed out. It just rounds the number to three decimal places. 9.13 rounded to 3 places just stays 9.13. If I understand you correctly, you want the numbers to be formatted all with exactly 3 decimal places. For that you would have to use some kind of string format expression. For example you could use this instead of print():
Depending on your preference you could print the like a list if you print the brackets and the commas manually also.