anonymous
  • anonymous
Hi, I'm on ps1b, can't figure out why my code won't take the sum of my changing variable ln. Thanks! prime=3.0 divisor=2.0 pcount=2.0 while pcount<1001.0: while (divisor
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
3rd line from the bottom, the sum (ln) part is messed up, the error says, print sum (ln)/prime TypeError: 'float' object is not iterable
anonymous
  • anonymous
sum is designed to add the elements of a list. Here ln is a scalar (a single value), not a list. Addition in Python is done using the + operator.
anonymous
  • anonymous
if the variable ln is changing every time, how would you set that up? would it add the previous natural logarithims of the variable 'prime' to the already existing one?

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
Here are a couple suggestions. If you want to keep a running sum in a loop, begin by defining that variable outside of the loop. It makes easier reading. For example: sum = 0 for x in range(1,10): sum = sum + x print sum At the end, 'sum' is the sum of the digits 1 through 9. Only put things in the loop that need to happen on every pass through the loop. For example, move 'import math' to the top of your program because it only needs to happen once.
anonymous
  • anonymous
i didnt understand/realize how to use the for loop. think I got it though, thanks!

Looking for something else?

Not the answer you are looking for? Search for more explanations.