(I couldn't get the former to work for me and don't know whether it's a version-based syntax change or an error or what).
2. Also, from your code:
sum = sum(log(primes)) # this is where I get an error message
First, you've defined
primes
earlier thus:
primes = (2, 3, 5, 7, 11, 13) # this is just as a test case
I'd have to look up the syntax, but that means
primes
is a tuple. I don't believe that
log(primes)
will work because
log
(or
math.log
) needs to operate on a float, it can't operate on the whole tuple--it sees this tuple of 2 3 5 7 11 13 and doesn't know which one to operate on. (It would be fairly easy to define a function to take a tuple of numbers > 0 and return another tuple containing the logs of those numbers, though.)
Also, I'm a little confused by your use of
sum
--did you previously initialize it to something not excerpted in your example code? Because
sum = sum(log(primes)) # this is where I get an error message
makes it look like
sum
is a function acting on something, and then the function is being assigned to itself. Which I guess you could do, but I don't think we've hit recursion yet (and that might not be the syntax to do it in Python anyway).
Ping me if you have any other questions (assuming someone more knowledgeable doesn't get to it first, of course), but hopefully that'll get you started.
no subject
Two things:
1. First thing to try is replace with (I couldn't get the former to work for me and don't know whether it's a version-based syntax change or an error or what).
2. Also, from your code:
First, you've defined earlier thus:
I'd have to look up the syntax, but that means is a tuple. I don't believe that will work because (or ) needs to operate on a float, it can't operate on the whole tuple--it sees this tuple of 2 3 5 7 11 13 and doesn't know which one to operate on. (It would be fairly easy to define a function to take a tuple of numbers > 0 and return another tuple containing the logs of those numbers, though.)
Also, I'm a little confused by your use of --did you previously initialize it to something not excerpted in your example code? Because
makes it look like is a function acting on something, and then the function is being assigned to itself. Which I guess you could do, but I don't think we've hit recursion yet (and that might not be the syntax to do it in Python anyway).
Ping me if you have any other questions (assuming someone more knowledgeable doesn't get to it first, of course), but hopefully that'll get you started.