[Tutor] HELP PLEASE
Joel Goldstick
joel.goldstick at gmail.com
Mon Aug 12 13:33:53 EDT 2019
On Mon, Aug 12, 2019 at 1:22 PM Marissa Russo <mrusso11 at u.rochester.edu> wrote:
>
> Hello,
>
> I am trying to figure out what is going on and why my output is saying “<function mean at …….>” instead of giving me a number. Please let me know if you see the error in my code!!
>
Marissa, you have lots of problems here. First, you should copy and
paste the complete traceback instead of the snippet you showed.
> import math
>
> def get_numbers():
> print("This program will compute the mean and standard deviation")
> file1 = input("Please enter the first filename: ")
> file2 = input("Please enter the second filename: ")
> x = open(file1, "r")
> y = open(file2, "r")
> nums = x.readlines()
> nums2 = y.readlines()
>
> return nums, nums2
>
Above. You are returning a string of all the data in your files.. is
that what you want?
> def mean(nums):
> for num in nums:
> _sum += num
> return _sum / len(nums)
>
Your traceback probably is complaining about _sum +=. You can't add
to a variable that doesn't exists. Maybe try _sum = 0 above your for
loop
> def mean2(nums2):
> for num in nums2:
> _sum += nums2
> return _sum / len(nums2)
>
> def main():
> data = get_numbers()
Ok, so you call a function which will return a tuple with two values
into data. But you don't do anything with data
You might put this here:
m = mean(data[0])
m2 = mean2(data[1])
then print m and m2
>
> print("The mean of the first file is: ", mean)
> print("The mean of the second file is: ", mean2)
> main()
>
So, first, show the complete error message here.
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
--
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
More information about the Tutor
mailing list