Forwarding to tutorblist for info...
-------- Forwarded Message -------- Subject: Re: [Tutor] HELP PLEASE Date: Mon, 12 Aug 2019 19:34:48 +0100 From: Alan Gauld <alan.ga...@yahoo.co.uk> Reply-To: alan.ga...@yahoo.co.uk To: Marissa Russo <mruss...@u.rochester.edu> On 12/08/2019 19:17, Marissa Russo wrote: > I fixed some things up??? OK, But please use ReplyAll when responding to list mails otherwise it just comes to me (or whoever posted) instead of the whole list. (And I might be busy. at the time..) > 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() > > num_copy = [] > for num in nums: > num_copy.append(float(num)) > nums = num_copy > > return nums You are only returning one list of numbers. you need to convert nums2 as well and then return both. To save some typing convert the?? int conversion loop into a function: def?? to_ints(strings): ?????? num_copy = [] ?????? for num in nums: ???????????????? num_copy.append(float(num)) ?????? return num_copy then call that on both list of strings. ???????????????? return to_ints(nums), to_ints(nums2) > def mean(): > _sum = 0 > return(sum(nums)/len(nums)) Notice you don't pass any values to mean so you are relying on the function seeing the values of nums outside the function somewhere. It is beter where you passs in the values as you did originally: def mean(numbers):.... > def main(): > data = get_numbers() > m = mean(data[0]) > m2 = mean2(data[1]) You call mean2() but don't have a mean2() function anymore. You only need mean() so call it both times but with different input data. > print("The mean of the first file is: ", m) > print("The mean of the second file is: ", m2) > main() > > This is now the output error: > Traceback (most recent call last): > File "/Applications/Python 3.7/exercises .py", line 34, in <module> > main() > File "/Applications/Python 3.7/exercises .py", line 30, in main > m = mean(data[0]) > TypeError: mean() takes 0 positional arguments but 1 was given See the comment above. You removed the input parameter to the mean() function. But then you call it as if it was still there. You must be consistent between your function definitions and function calls.. You need to start thinking like the interpreter as you walk through the code. Think about what it knows at any given point and how the various functions communicate?? - usually by storing intermediate results in variables. (Many find it convenient to jot down the variables and their values as they walk through the code, updating the values as they go). So check what those variables contain - using print statements to debug it if necessary. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor