Re: [Tutor] HELP PLEASE

2019-08-13 Thread Sithembewena L. Dube
Hi Marissa,

I really think that you could consider doing an introductory Python
tutorial and then venture back into solving this problem.

Understanding concepts like data types, function syntax and loops makes all
the difference in approaching programming challenges.

Here is a decent and free online Python tutorial to get you going:
https://www.learnpython.org/


Kind regards,
Sithembewena Dube


*Sent with Shift
*

On Tue, Aug 13, 2019 at 12:47 PM Cameron Simpson  wrote:

> On 12Aug2019 15:11, Marissa Russo  wrote:
> >This is my code:
>
> Thank you.
>
> >This is the output of my updated code:
> >Traceback (most recent call last):
> >  File "/Applications/Python 3.7/exercises .py", line 37, in 
> >main()
> >  File "/Applications/Python 3.7/exercises .py", line 33, in main
> >m = mean(data[0])
> >  File "/Applications/Python 3.7/exercises .py", line 29, in mean
> >return(sum(nums)/len(nums))
> >TypeError: unsupported operand type(s) for +: 'int' and 'str'
>
> Thank you for this as well, it makes things much clearer.
>
> So, to your code:
>
> >import math
>
> Just a remark: you're not using anything from this module. I presume you
> intend to later.
>
> >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()
>
> As has been mentioned in another reply, readlines() returns a list of
> strings, one for each line of text in the file.
>
> In order to treat these as numbers you need to convert them.
>
> >return nums, nums2
> >
> >def to_ints(strings):
> >num_copy = []
> >for num in nums:
> >num_copy.append(float(num))
> >return num_copy
>
> This returns a list of floats. You might want to rename this function to
> "to_floats". Just for clarity.
>
> >return to_ints(nums), to_ints(nums2)
>
> This isn't reached. I _think_ you need to put this line at the bottom of
> the get_numbers function in order to return two lists of numbers. But it
> is down here, not up there.
>
> >def mean(nums):
> >_sum = 0
> >return(sum(nums)/len(nums))
>
> This is the line raising your exception. The reference to "+" is because
> sum() does addition. It starts with 0 and adds the values you give it,
> but you're handing it "nums".
>
> Presently "nums" is a list of strings, thus the addition of the initial
> 0 to a str in the exception message.
>
> If you move your misplaced "return to_ints(nums), to_ints(nums2)"
> statement up into the get_numbers function you should be better off,
> because then it will return a list of numbers, not strings.
>
> Cheers,
> Cameron Simpson 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] HELP PLEASE

2019-08-12 Thread Sithembewena L. Dube
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
*

On Mon, Aug 12, 2019 at 7:24 PM Marissa Russo 
wrote:

> Hello,
>
> I am trying to figure out what is going on and why my output is saying
> “” 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@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python and Django dev available

2019-08-01 Thread Sithembewena L. Dube
Hi everyone,

I'm a developer with just over 10 years' experience under my belt. I've
worked with many languages and frameworks, including the popular Django web
framework.

I'm currently in the market for remote opportunities. Please reply if
looking for a resource. Serious enquiries only please.


Kind regards,
Sithembewena

*Sent with Shift
*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor