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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:23:12+00:00 2026-05-26T14:23:12+00:00

I need to test whether each number from 1 to 1000 is a multiple

  • 0

I need to test whether each number from 1 to 1000 is a multiple of 3 or a multiple of 5.

I tried this code in Python 2.x:

n = 0
s = 0

while (n < 1001):
    x = n/3
    if isinstance(x, (int, long)):
        print 'Multiple of 3!'
        s = s + n
    if False:
        y = n/5
        if isinstance(y, (int, long)):
            s = s + n

    print 'Number: '
    print n
    print 'Sum:'
    print s
    n = n + 1

The idea is to try dividing the number and see if the result is an integer. However, I’m not getting the expected result.

How do I test whether the number is an integer?


In 2.x, division like this will produce an integer, discarding the remainder; see How can I force division to be floating point? Division keeps rounding down to 0? for details.

In 3.x, the division will produce a floating-point value; the result is not "an integer" even if it is a whole number, so the isinstance check will fail. See Why does integer division yield a float instead of another integer? for details.

If you need the remainder from integer division rather than just testing for divisibility, see Find the division remainder of a number.

  • 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-05-26T14:23:12+00:00Added an answer on May 26, 2026 at 2:23 pm

    You do this using the modulus operator, %

    n % k == 0
    

    evaluates true if and only if n is an exact multiple of k. In elementary maths this is known as the remainder from a division.

    In your current approach you perform a division and the result will be either

    • always an integer if you use integer division, or
    • always a float if you use floating point division.

    It’s just the wrong way to go about testing divisibility.

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

Sidebar

Related Questions

I'm reading text from a flat file in c# and need to test whether
In Python I need to efficiently and generically test whether an attribute of a
In my code, I need to test whether specified column is null and the
I need to test whether each item in an array is identical to each
I need to test whether various types of database objects exist in a given
We're contemplating Visual Studio licensing and need to decide whether licenses for Architecture/Database/Test editions
I need to test a JDBC connection to a database. The java code to
I basically need a function to check whether a string's characters (each character) is
I have bunch of methods in which i need to test whether remote server
Easy question this time. I'm trying to test whether or not a string does

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.