[Tutor] HELP PLEASE
Sithembewena L. Dube
zebra05 at gmail.com
Mon Aug 12 13:36:29 EDT 2019
In your calls to the `*print*` function, you are not calling the `*mean*`
and `*mean2*` functions that you declared to calculate averages. So Python
sees you trying to concatenate two function objects to strings and is not
happy. That's one thing.
Secondly, your code could be refactored to define one `*mean*` function as
your functions do virtually the same thing. Then, you could just call it as
needed.
Thirdly, you could use the `*with*` keyword. See "7.2. Reading and Writing
Files" at https://docs.python.org/3/tutorial/inputoutput.html
Kind regards,
Sithembewena Dube
*Sent with Shift
<https://tryshift.com/?utm_source=SentWithShift&utm_campaign=Sent%20with%20Shift%20Signature&utm_medium=Email%20Signature&utm_content=General%20Email%20Group>*
On Mon, Aug 12, 2019 at 7:24 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!!
>
> 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
>
> def mean(nums):
> for num in nums:
> _sum += num
> return _sum / len(nums)
>
> def mean2(nums2):
> for num in nums2:
> _sum += nums2
> return _sum / len(nums2)
>
> def main():
> data = get_numbers()
>
> print("The mean of the first file is: ", mean)
> print("The mean of the second file is: ", mean2)
> main()
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list