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 8242863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:18:42+00:00 2026-06-07T21:18:42+00:00

I am a beginner at python (one week). Here I am trying print the

  • 0

I am a beginner at python (one week). Here I am trying print the list of all the prime factor of 60. But for line 19, I am getting following error:
TypeError: unsupported operand type(s) for %: ‘float’ and ‘list’

The code:

whylist = []
factor = []
boom = []
primefactor = []
n = 60
j = (list(range(1, n, 1)))



for numbers in j:
    if n%numbers == 0:
        whylist.append(numbers)
        for everynumber in whylist:
            factor.append(everynumber)

for things in factor:
    u = (list(range(1, things, 1)))
    d = float(things)
    if d%u == 0:
        boom.append(things)
    if len(boom) == 1:
        for every in boom:
            primefactor.append(every)
print(primefactor)

What am I doing wrong?

  • 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-07T21:18:44+00:00Added an answer on June 7, 2026 at 9:18 pm

    To apply a math operation to every element in a list you can use a list-comprehension:

    new_list = [ x%num for x in old_list]
    

    There are other ways to do it as well. Sometimes people will use map

    new_list = map(lambda x: x%num, old_list)
    

    but most people prefer the first form which is generally more efficient and clear than using lambda (which can be a little confusing when you’re just starting to learn python).

    EDIT

    Here’s a recursive implementation of what you were trying:

    def factorize(n):
        out=[]
        for i in range(2,n):
            if(n%i == 0): #first thing to hit this is always prime
                out.append(i) #add it to the list
                out+=factorize(n/i)  #get the list of primes from the other factor and append to this list.
                return out
            else:
                return [n] # n%i was never 0, must be prime.
    
    print factorize(2000)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Python beginner here, I have a list of lists and want to refer to
Python beginner here. I've looked around and found similar questions but can't quite cobble
Right I am a complete beginner here, trying to work through various python tutorials
Python beginner here. I have a text file that is sorted into columns: fields
I am a beginner of Python. I am trying now figuring out why the
I am quite a beginner to Python and trying to get my head around
I'm almost an absolute beginner in Python, but I am asked to manage some
Django advanced beginner here. I'm banging my head against the wall trying to figure
Python beginner here. I am using the matplotlib library to make graphs from tab
I'm python beginner: how can I iterate over csv files in one directory and

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.