Python Forum
Divide a number by numbers in a list.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Divide a number by numbers in a list.
#1
Hello. Im trying to get the sum of all prime numbers under 2,000,000. In my code Ive tried to divide a number with only prime numbers in order to lower the amounts of iterations. The code, however, wont read my list of prime numbers as an integer and I get this error.
Error:
Traceback (most recent call last): File "python", line 7, in <module> TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'
This is my code
primes = [2, 3]
sum = 5
test = 5
counter = 0

while counter < 10000:
  for i in range(1, int(test**0.5)+1, int(primes)):
    if i > 0:
      if test % i != 0:
        primes.append(i)
        sum += test
  counter += 2
  test += 2

print(sum)
How can I make my code read the list as an integer?
Reply


Messages In This Thread
Divide a number by numbers in a list. - by Wallen - Sep-14-2018, 01:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I calculate a ratio from 2 numbers and return an equivalent list of about 1000 Pleiades 8 15,857 Jan-05-2024, 08:30 PM
Last Post: sgrey
  Delete strings from a list to create a new only number list Dvdscot 8 1,651 May-01-2023, 09:06 PM
Last Post: deanhystad
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,379 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  List of random numbers astral_travel 17 2,845 Dec-02-2022, 10:37 PM
Last Post: deanhystad
  Remove numbers from a list menator01 4 1,419 Nov-13-2022, 01:27 AM
Last Post: menator01
  [split] why can't i create a list of numbers (ints) with random.randrange() astral_travel 7 1,614 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 4,975 Jul-01-2022, 01:23 PM
Last Post: deanhystad
  Split a number to list and list sum must be number sunny9495 5 2,373 Apr-28-2022, 09:32 AM
Last Post: Dexty
  When did the number got included in the list? Frankduc 14 3,253 Feb-03-2022, 03:47 PM
Last Post: Frankduc
  producing numbers out of a list bouraque7878 10 3,889 Nov-12-2021, 09:13 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020