Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9223765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:09:03+00:00 2026-06-18T04:09:03+00:00

def getPrimeList(check): storedprimes = [] i = 2 while i <= check: if isPrime(check):

  • 0
def getPrimeList(check):
    storedprimes = []
    i = 2
    while i <= check:
        if isPrime(check):
            storedprimes = storedprimes + [i]
        i = i + 1
    return storedprimes
def getPrimeFact(check):
    primelist = getPrimeList(check)
    prime_fact = []
    i = 0
    while check !=1:
        if check%primelist[i]==0:
            prime_fact=prime_fact+[primelist[i]]
            check = check/primelist[i]
        i = i + 1
        if i == len(primelist):
            i = 0
    return prime_fact
def getGCF(checks):
    a=0
    listofprimefacts=[]
    while a<len(checks):
        listofprimefacts=listofprimefacts+[getPrimeFact(checks[a])]
        a=a+1
    b=0
    storedprimes=[]
    while b<len(primefactlist):
        c=0
        while c<len(listofprimefacts[b]):
            if listofprimefacts[b][c] not in storedprimes:
                storedprimes=storedprimes+[listofprimefacts[b][c]]
            c=c+1
        b=b+1
    prime_exp=[]
    d=0
    while d<len(storedprimes):
        prime_exp=prime_exp+[0]
        d=d+1

    e=0
    while e<len(storedprimes):
        f=0
        while f<len(listofprimefacts):
            if f==0:
                prime_exp[e]=listofprimefacts[f].count(storedprimes[e])
            elif prime_exp[e]-(listofprimefacts[f].count(storedprimes[e]))>0:
                prime_exp[e]=listofprimefacts[f].count(storedprimes[e])                
            f=f+1
        e=e+1
    g=0
    GCF=1
    while g<len(primelist):
        GCF=GCF*(storedprime[g]**prime_exp[g])
        g=g+1
    return GCF

I am creating a program that will use these functions for the purpose of calculating fractions; however, after testing my GCF function in the shell I keep getting a list indexing error. I have no idea, where the error is coming from considering im 99% sure there is no problems with my indexes, usually i would not post such a “fixable” problem in SO but this time i just have no idea what the problem is, thanks again.

Oh and heres the exact error

File "<pyshell#1>", line 1, in <module>
    getGCF(checks)
  File "E:\CompProgramming\MidtermFuncts.py", line 31, in getGCF
    listofprimefacts=listofprimefacts+[getPrimeFact(checks[a])]
  File "E:\CompProgramming\MidtermFuncts.py", line 20, in getPrimeFact
    if check%primelist[i]==0:
IndexError: list index out of range
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:09:05+00:00Added an answer on June 18, 2026 at 4:09 am

    You mixed up i and check in your getPrimeList() function; you test if check is a prime, not i; here is the correct function:

    def getPrimeList(check):
        storedprimes = []
        i = 2
        while i <= check:
            if isPrime(i):  # *not* `check`! 
                storedprimes = storedprimes + [i]
            i = i + 1
        return storedprimes
    

    This, primelist will be set to an empty list (as getPrimeList(check) returns an empty list) and your primelist[i] (for any i) will fail with an index error.

    Another way for primelist to be empty is when isPrime() never returns True; you don’t show us that function to verify it.

    Your next error is in getGCF(); you define a listofprimefacts variable (a list) first, but later refer to a non-existing primefactlist variable, leading to a NameError. The next name error is going to be primelist further in that function.

    You really want to re-read the Python tutorial; you are missing out on many python idioms in your code; specifically on how to create loops over sequences (hint: for check in checks: is easier to use than a while loop with an index variable) and how to append items to a list.

    My personal toolkit defines this:

    from math import sqrt
    
    def prime_factors(num, start=2):
        """Return all prime factors (ordered) of num in a list"""
        candidates = xrange(start, int(sqrt(num)) + 1)
        factor = next((x for x in candidates if (num % x == 0)), None)
        return ([factor] + prime_factors(num / factor, factor) if factor else [num])
    

    which doesn’t need a isPrime() test.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

def fun1(a): for i in range(len(a)): a[i] = a[i] * a[i] return a
def download_if_dne(href, filename): if os.path.isfile(filename): # print 'already downloaded:', href return False else: if
def self.get(server) return unless server server = server.to_s if klass = @handlers[server] obj =
def record return unless @supported klasses = profile_options[:formats].map { |f| RubyProf.const_get(#{f.to_s.camelize}Printer) }.compact klasses.each do
def summation(calc_termo, linf, prox, lsup): soma = 0 while linf <= lsup: soma =
def filter(f, lst): if lst == []: return [] if f(lst[0]): return [lst[0]] +
def makecounter(): return collections.defaultdict(int) class RankedIndex(object): def __init__(self): self._inverted_index = collections.defaultdict(list) self._documents = []
def isBig(x): if x > 4: return 'apple' else: return 'orange' This works: if
def primes(n): if n==2: return [2] elif n<2: return [] s=range(3,n+1,2) mroot = n
def digits(n): res = [] while n > 0: res.append(n % 10) n /=

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.