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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:51:24+00:00 2026-06-08T07:51:24+00:00

This code will be part of a program that will check if a number

  • 0

This code will be part of a program that will check if a number is prime or not. I know it’s not particularly elegant, but I want to get it working simply for experience. I think that the function is failing because the logic on the if/elif is wrong, when I run this code, it seems to just go straight to the else clause. Is this a syntax problem, or am I not allowed to do logic checks in if clauses?

list = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]

def find_prime(list, n):
    if n in list == False:
        list.append(n)
        print "I'ts in there now."
    elif n in list == True:
        print "It's in there already."
    else:
        print "Error"

find_prime(list, 3)
find_prime(list, 51)
  • 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-08T07:51:27+00:00Added an answer on June 8, 2026 at 7:51 am
    1. list is a bad name for a variable. It masks the built-in list.

    2. if n in list == True: doesn’t do what you await: 1 in [0, 1] == True returns False (because, as @Duncan notes, 1 in [0,1] == True is shorthand for 1 in [0,1] and [0,1] == True). Use if n in li: and if n not in li:

    3. No reason for an Error, since an element is in the list or it is not in the list. Anything else is programming error.

    So your code could look like this:

    li = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
    
    def find_prime(li, n):
        if n in li:
            print "It's in there already."
        else:
            li.append(n)
            print "It's in there now."
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I will keep this quick. The attached code for the most part works i
this code will not pass the query string to default3.aspx on Image Button ..
I am unsure why this code will not work. When I click a button
Can anyone please suggest me whether this code will cause concurrency or not. This
This is for a homework assignment, so I don't want the exact code, but
I am currently writing a program that will read part of the windows system
#post The names of my variables are not imporant! This code will be deleted
I this part of code, instructs my program (which make screenshots) to spawn a
I created a Java program that will process files using a C++ program. This
This is a 2 part question. 1) Is there some sort of program that

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.