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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:52:37+00:00 2026-06-09T01:52:37+00:00

I am doing a ranking type thing, what happens is I compare the score

  • 0

I am doing a ranking type thing, what happens is I compare the score to the current score and if the score is lower then the current then the player has got a high score, but when using this code here

        print "Score = " + str(score) + ", Compared to = " + str(array[x])
        if score < array[x]:
                #Do stuff here

But even if score is 4 and array[x] is 2 the if statement is still done?

Am I doing something wrong?

My understanding is that if score 4 and array[x] is 2 then 4 is greater than 2 which means it comes back False?


Heres the full code

def getRank(array, score):
    rank = 0
    rankSet = False
    for x in range(0, len(array)):
        print "Score = " + str(score) + ", Compared to = " + str(array[x])
        if score < array[x]:
            if not rankSet:
                rank = x
                print "Set rank to: " + str(rank)
                rankSet = True
        elif score == array[x] or score > array[x]:
            rank += 1
            print "Rank higher than " + str(x)
    print "Rank = " + str(rank)
    return rank

it prints this if score = 4 and the array is made up of [1, 2]

Score = 4, Compared to = 1
Set rank to: 0
Score = 4, Compared to = 2
Rank = 0
  • 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-09T01:52:39+00:00Added an answer on June 9, 2026 at 1:52 am

    Check to make sure that both score and array[x] are numerical types. You might be comparing an integer to a string…which is heartbreakingly possible in Python 2.x.

    >>> 2 < "2"
    True
    >>> 2 > "2"
    False
    >>> 2 == "2"
    False
    

    Edit

    Further explanation: How does Python compare string and int?

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

Sidebar

Related Questions

Current, I've got a stored procedure that has a main goal of doing a
Doing an ajax get request works as expected using the following code: $.ajax({ type:
Doing a simple Squeryl database lookup, but trying to exclude a value. I've tried:
I have a thing I'm doing where I need a webpage to stream a
This one has be stumped. I'm doing some work on a legacy ASP.NET WebForms
I've got a gaming-oriented website with 200+ users. The site has a large database
I'm doing some math with really big numbers (I'm using Python, but this question
I've got the following query to determine how many votes a story has received:
I'm doing some research on ranking algorithms, and would like to, given a sorted
I have a high score database for a game that tracks every play in

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.