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.
#3
(Sep-14-2018, 01:56 PM)ichabod801 Wrote: You can't. I don't understand what you are trying to do there. int(primes) is being given as the step argument to the range function. You can't step through a sequence by multiple distances at the same time. If you want to loop through the primes to test each one against counter, you should just use for prime in primes:.

So the idea is that its ineficiant to divide a nummer, lets say 541, by every odd nummer up to the square root of 541. So I attempted to create a list were new primes are added as the code iterates and then only dividing the next number to be tested with primes from that list. In this way we don’t need to divide by every odd number, 3, 5, 7, 9 ect. And in this way focus on dividing by the primes, 3, 5, 7, 11 ect.

So you think I should change
for i in range(1, int(test**0.5)+1, int(primes)):
With

for prime in primes(1, int(test**0.5)+1, prime):
English is not my first language so feel free to speak your mind if I’m not clear enough, and I’ll try to explain better :)
Reply


Messages In This Thread
Divide a number by numbers in a list. - by Wallen - Sep-14-2018, 01:46 PM
RE: Divide a number by numbers in a list. - by Wallen - Sep-14-2018, 03: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,818 Jan-05-2024, 08:30 PM
Last Post: sgrey
  Delete strings from a list to create a new only number list Dvdscot 8 1,602 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,330 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  List of random numbers astral_travel 17 2,805 Dec-02-2022, 10:37 PM
Last Post: deanhystad
  Remove numbers from a list menator01 4 1,388 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,584 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 4,951 Jul-01-2022, 01:23 PM
Last Post: deanhystad
  Split a number to list and list sum must be number sunny9495 5 2,353 Apr-28-2022, 09:32 AM
Last Post: Dexty
  When did the number got included in the list? Frankduc 14 3,189 Feb-03-2022, 03:47 PM
Last Post: Frankduc
  producing numbers out of a list bouraque7878 10 3,835 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