Exercise 4.4: Improve a program
Closed this issue · 2 comments
Hey,
I keep receiving the following error for my solution of Exercise 4.4. (ERROR: Hmmm... It seems you are either not extracting densities or not adding constants to the dictionary.)
My final solution is correct and numpy is not showing any error. I'm not sure what am I missing here.
below is my code:
Uncomment and modify the following code. Do not change variable names for testing purposes.
def read_densities_join(filename):
with open(filename, "r") as infile:
list_joined = {}
for line in infile:
columns = line.split()
if len(columns) > 1:
densities = float(columns[-1])
substance = "_".join(columns[:-1])
list_joined[substance] = densities
return list_joined
densities = read_densities_join("data/densities.dat")
print(densities)
def read_densities_substrings(filename):
with open(filename, "r") as infile:
list_sub = {}
for line in infile:
densities_2 = line[12:].strip()
substance_2 = line[:12].strip()
densities_names = substance_2.replace(" ", "_")
list_sub[densities_names] = float(densities_2)
return list_sub
densities_2 = read_densities_substrings("data/densities.dat")
print(densities_2)
Hi @esemsc-b7ff6690, we are glad to see you are making progress. Here is the explanation from README.md
which I addresses your questions I think:
Although PyBryt provides much more detailed feedback, it is possible it complains about your code even though assert statement confirms your code is correct. This is because PyBryt testing is based on comparing your solution to reference solutions. Since there is virtually an infinite number of alternative solutions, it is possible that your solution is not in our references. On the other hand, assert statements check the final result of your code and if they do not raise an error, your code is correct and you do not have to address PyBryt's error messages (if any).
Awesome ! Thank you