'I cant figure out the right solution yet i feel so close. Anyone can help me out/
Metric Dictionary Write a function that calculates the mean, median, variance, standard deviation, minimum and maximum of of list of items. You can assume the given list is contains only numerical entries, and you may use numpy functions to do this.
def dictionary_of_metrics(items):
gauteng = {
'mean': round(np.mean(items),2),
'median': round(np.median(items),2),
'std': round(np.std(items), 2),
'var': round(np.var(items),2),
'min': round(np.min(items),2),
'max': round(np.max(items),2) }
return gauteng
This is the error message I get
NameError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_10816/1906678183.py in ----> 1 dictionary_of_metrics(gauteng)
NameError: name 'gauteng' is not defined
Solution 1:[1]
Did you create the list of items list called 'gauteng' before calling the function? If not, you have to create the list of items before using it as a function argument. The code would be
def dictionary_of_metrics(items):
gauteng = {
'mean': round(np.mean(items),2),
'median': round(np.median(items),2),
'std': round(np.std(items), 2),
'var': round(np.var(items),2),
'min': round(np.min(items),2),
'max': round(np.max(items),2) }
return gauteng
gauteng = [1,2,3,4,5]
dictionary_of_metrics(gauteng)
The function creates the gauteng dictionary in it's local scope. This cannot be accessed globally and it cannot be used for as function argument.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Adnan taufique |
