Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 nested for loop dilemma 2
#11
(Sep-12-2019, 12:21 PM)perfringo Wrote: I am afraid that you are very far from determining primes.

Maybe something along those lines:

def prime_checker(integer): 
    if integer == 2:                        # eliminate 2
        return True 
    if integer == 1 or integer % 2 == 0:    # eliminate 1 and all even integers
        return False 
    for i in range(3, integer, 2):          # divide only with odd numbers as integer can't be even
        if integer % i == 0: 
            return False 
    else: 
        return True

Very elaborate and sensible, I see now my very last attempts using if + and + or is rather flawed and the first if + for loop was closer to the truth however inefficient?

To tell the truth I haven't ever dug this deep in primes and my math skills I cannot brag about.
I just have so many tasks to get done so I am trying to rush through it without giving some of them the required thought like with this one.

I appreciate your input perfringo thanks for all the help.
Quote
#12
(Sep-12-2019, 12:41 PM)YoungGrassHopper Wrote: I just have so many tasks to get done so I am trying to rush through it without giving some of them the required thought like with this one.

There are always couple of minutes to spare before you start coding. Think in simple terms - what you have, what you want etc. Otherwise - mess in your head will transform into mess in your code. For starters it's good to spell out plan or solution in spoken language and then translate it into Python. If you don't formulate what you want to accomplish you are not able to write code which delivers expected results.
YoungGrassHopper and newbieAuggie2019 like this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Quote
#13
(Sep-12-2019, 01:04 PM)perfringo Wrote:
(Sep-12-2019, 12:41 PM)YoungGrassHopper Wrote: I just have so many tasks to get done so I am trying to rush through it without giving some of them the required thought like with this one.

There are always couple of minutes to spare before you start coding. Think in simple terms - what you have, what you want etc. Otherwise - mess in your head will transform into mess in your code. For starters it's good to spell out plan or solution in spoken language and then translate it into Python. If you don't formulate what you want to accomplish you are not able to write code which delivers expected results.

Thanks for the golden advice perfringo it makes sense. And I believe its imperative that I start doing it now in the very early stages whilst laying the foundation in order to cultivate a sound coding mindset.

I apologise for all the cringing dumb mistakes I make, I hope that with practice and experience it will improve, until then please bare with my noobness haha and thanks for all the support.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Nested Loop for user input Ads 2 176 Dec-30-2019, 11:44 AM
Last Post: Ads
  openpyxl nested for loop help rmrten 3 422 Oct-16-2019, 03:11 PM
Last Post: stullis
  nested for loop dilemma YoungGrassHopper 9 448 Sep-13-2019, 03:56 AM
Last Post: jsira2003
  Nested while loop problem + turtle DreamingInsanity 3 471 Jul-06-2019, 02:01 PM
Last Post: DreamingInsanity
  Index error using pop in nested loop PerksPlus 3 549 Mar-28-2019, 03:11 PM
Last Post: ichabod801
  Nested for loop strange problem mcva 2 471 Mar-16-2019, 12:53 PM
Last Post: mcva
  Nested while loop in pyramid program. raj55 2 2,190 May-04-2018, 10:05 AM
Last Post: ThiefOfTime
  Nested Loop Problem GSWes 5 1,439 Nov-12-2017, 10:22 PM
Last Post: Larz60+
  Using nested for loop with a single list mikeavison 3 1,105 Aug-12-2017, 08:13 PM
Last Post: ichabod801
  A "Nested Loop" example from python 3.3.4 to 2.6!! sarada2099 6 2,573 Dec-18-2016, 02:56 PM
Last Post: sarada2099

Forum Jump:


Users browsing this thread: 1 Guest(s)