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

  • Home
  • SEARCH
  • 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 8315783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:12:38+00:00 2026-06-08T21:12:38+00:00

this code is working fine. say for 1980 it gives the result 2 ^

  • 0

this code is working fine. say for 1980 it gives the result 2 ^ 2 *3 ^ 2 *5 ^ 1 *7 ^ 0 *11 ^ 1 *(an extra asterisk remains at the end. i can remove it. and that has nothing to with my problem.
the code is:

prime=[2,3,5]
f=7
def next_prime(f):
    j=0
    while j==0:
        for x in prime:
            if f%x==0:
                f+=2
                break
        else:
            j=1
    return f;
def factorization(n):
    list=[2,3,5]
    power=[]
    x=0
    while x<len(list):
        j=0
        while n%list[x]==0:
            j+=1
            n=n/list[x]
        power.append(j)
        x+=1
    if n!=1:
        while n!=1:
            g=next_prime(f)
            j=0
            while n%g==0:
                j+=1
                n=n/g
            else:
                power.append(j)
                prime.append(g)
    x=0
    while x<len(power):
        print(prime[x],"^",power[x],"*",end="")
        x+=1

factorization(1980)

then if i want to remove the term 7 ^ 0 from the result therefore all the primes which have the power zero, i made change in line 31 (if j!=0: instead of else:). and then the code’s not working. it’s working for numbers like 13860 where no prime has the power zero not in numbers like 1980. i can’t find the problem!
the changed code is:

prime=[2,3,5]
f=7
def next_prime(f):
    j=0
    while j==0:
        for x in prime:
            if f%x==0:
                f+=2
                break
        else:
            j=1
    return f;
def factorization(n):
    list=[2,3,5]
    power=[]
    x=0
    while x<len(list):
        j=0
        while n%list[x]==0:
            j+=1
            n=n/list[x]
        power.append(j)
        x+=1
    if n!=1:
        while n!=1:
            g=next_prime(f)
            j=0
            while n%g==0:
                j+=1
                n=n/g
            if j!=0:
                power.append(j)
                prime.append(g)
    x=0
    while x<len(power):
        print(prime[x],"^",power[x],"*",end="")
        x+=1

factorization(1980)
  • 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-08T21:12:40+00:00Added an answer on June 8, 2026 at 9:12 pm

    I haven’t analyzed your logic, but you’re using else clause wrongly. while .. else makes sense only if you call a break inside your while. In your first code sample, the else branch is always executed.

    As example, even the following code will run else branch:

    while False:
        print 'while'
    else:
        print 'else'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So basically this code was working fine before. I had some computer issues and
Hi Javascript gurus, I have this Javascript code which is working fine on Firefox
I have this set of code which was working fine about an hour or
<a href=details.php?phoneid=1><img src=phone01.jpg></a> When I write the code like this it's working fine. But
i been working in the login code .. it works fine except this message
Why isn't this code working? The app loads fine, however whenever I press the
$(#maincontent).animate({top:450px},1200) .html($(#+Lidentity).html()) .animate({top:0px},1000); Hi friends, This is jquery code, which is working fine. As
I have this code working in C#: var request = (HttpWebRequest)WebRequest.Create(https://x.com/service); request.Method = GET;
Why isn't this code working? I've been stuck on this for 2 days. public
I used to have this code working with my Tomcat server: HttpRequestBase targetRequest =

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.