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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:04:41+00:00 2026-06-01T18:04:41+00:00

this is my first post here. I’m new to Python and programming in general

  • 0

this is my first post here. I’m new to Python and programming in general so I’m not sure where I went wrong. This is a solution I came up with to Problem #52 on Project Euler (I know it’s probably not the best way either). My problem with this code is that the while statement doesn’t break when it gets to the correct answer. It’ll catch it and give me the answer only if I started num with the correct answer: 142857, but when I initialize it with anything else it continues counting right past 142857. The strange thing is I used the same exact method to answer another Euler Problem and that one works just fine. Can anyone please tell me why this is happening here? Thanks!

def digits(number):
    return [int(x) for x in str(number)]

def same_digits():
    num = 1
    x2 = sorted(digits(num*2))
    x3 = sorted(digits(num*3))
    x4 = sorted(digits(num*4))
    x5 = sorted(digits(num*5))
    x6 = sorted(digits(num*6))

    while x2 != x3 != x4 != x5 != x6:
        num += 1
    print num
  • 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-01T18:04:43+00:00Added an answer on June 1, 2026 at 6:04 pm

    The variables x2 etc. are not changed inside the loop, so they will always keep their initial values. If you want their values to be recalculated when num changes, you need to move that code into the loop.

    Moreover, you are using comparison operator chaining here. The expression

    x2 != x3 != x4 != x5 != x6
    

    is equivalent to

    x2 != x3 and x3 != x4 and x4 != x5 and x5 != x6
    

    which probably isn’t what you want.

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

Sidebar

Related Questions

this is my first post here. I'm new in Android Programming. I want to
I'm new to Java and this is my first post on here so hopefully
this is my first post here. First off, some background, I'm new to C#
I'm new to Objective-C. This is my first post here. I created a singleton
my first post here. I'm not new to JQuery, but I find complex coding
This is my first post here in StackOverflow. I am not a newbie to
This is my first post here. I have a problem. I need to take
this is my first post here on stackoverflow and am very impressed by the
My first post here, so i hope this is the right area. I am
This is my first time here so I hope I post this question at

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.