In: Computer Science
A chemist is performing four experiments and each experiment has five results. The results for each experiment are given in the following table. An experiment is considered successful if the average of the five test results for a given experiment is between 25 and 32. Using a nested loop, write a script that (Python):
- Compute and display the test results average for each experiment
- Indicate is the experiment was successful or not
1st Results | 49.1 | 15.8 | 16.9 | 25.2 | 33.4 |
2nd Results | 34.8 | 45.2 | 27.9 | 36.8 | 23.4 |
3rd Results | 26.4 | 16.8 | 10.2 | 15.8 | 18.9 |
4th Results | 26.9 | 19.5 | 42.9 | 42.5 | 27.4 |
Hint : Use lists to store each experiment results and a single list to store the entire table
If you have any doubts, please give me comment...
experiment_results = [[49.1, 15.8, 16.9, 25.2, 33.4], [34.8, 45.2, 27.9, 36.8, 23.4],
[26.4, 16.8, 10.2, 15.8, 18.9], [26.9, 19.5, 42.9, 42.5, 27.4]]
experiment_no = 1
isSuccessfull = True
for experiment in experiment_results:
s = 0
for result in experiment:
s += result
avg = s/len(experiment)
print(experiment_no, end=':\t')
for result in experiment:
print(result, end='\t')
print("%.2f"%avg)
if avg<25 or avg>32:
isSuccessfull = False
experiment_no+=1
if isSuccessfull:
print("Experiment was successful")
else:
print("Experiment was not successful")