#3.py
 
# Using a simple library we have written
# The library can read numbers from a file and give you mean and variance through
# function calls
 
from stats import *

# ** We are going to run the same program as in 1.py on another file called baddata.py
#     which has alphanumerics like tom, 1j2, etc. What will happen? **
 
def main():
 
    print(" Calling functions from the library .... \n")
 
    average,variance,n = mnvar("baddata.txt")
 
    print(" average = ",average," variance = ",variance, "based on ",n," data points")
 
    average,n = mean("baddata.txt")
 
    print(" average = ", average,"based on ",n," data points")
 
 
main()
 
# Here is what Python says
 
'''
Traceback (most recent call last):
  File "/Users/rego/Documents/3.py", line 26, in <module>
    main()
  File "/Users/rego/Documents/3.py", line 17, in main
    average,variance,n = mnvar("baddata.txt")
  File "/Users/rego/Documents/stats.py", line 19, in mnvar
    newdata = float(line)
ValueError: could not convert string to float: 'tom\n'
 
'''
 
#So clearly, it is getting strings that it cannot convert into numbers (ValueError)
 
