0
Hello Stackoverflow community, good morning.
I’m trying to develop a code that calculates the numerical values obtained from a physics equation
Here is the form of the equation,
where k , T and pi are user-defined constant values. Already lambda is a value that will be traversed within a range with for and its responses stored in a list using the following code snippet
import pandas as pd
import numpy as np
k=2.0
T=25.0+273.0
rhos=[]
for i in range (1,100):
rho = (8*np.pi*k)/i
rhos.append(rho)
print (rhos)
the results are coming out in this format :
How do I control how many decimals will appear on the list? This control can be done before filling in the list or only after filling in the append method?
EDIT 1 : I tried to adjust the code as follows,
import pandas as pd
import numpy as np
k=2.0
T=25.0+273.0
rhos=[]
for i in range (1,100):
rho = (8*np.pi*k)/i
rhos.append(rho)
print( ".4f" % rho )
However I am getting this error message, apparently I converted the strings to text when filling the list.
I will give a study on the chapter formatting with % and try to adjust the code,
until then, thanks to Marcelo for helping the/
Unfortunately I couldn’t :/ The idea was to display the list of values only once after the list had been filled in with the values of the equation. I tried to do as you suggested but I think I did something wrong, follow a print of the result and code
– Kioolz
Sorry, I forgot to put the % in the example, the correct print would be print( "%.4f" %Rho ). In the rest your code will work
– Marcello Moreira
Oops, I just saw your reply. I later edit with the result. :)
– Kioolz
Buddy, it didn’t work. I don’t understand why :(
– Kioolz