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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:57:57+00:00 2026-06-09T17:57:57+00:00

I have a program to quiz me on how far planets are from the

  • 0

I have a program to quiz me on how far planets are from the sun. The only problem is, no matter what answer I put it always shows up as correct. Here is a link to my code: http://pastebin.com/MimECyjm

If possible, I would like a more simplistic answer because I am not that proficient in python yet

Code in question:

mercury = "57.9"
mercury2 = "57900000"

def Mercury():
    ans = raw_input("How far is Mercury from the sun? ")
    if mercury or mercury2 in ans:
        print "Correct!"
        time.sleep(.5)
        os.system("cls")
        main()
    else:
        print "Incorrect!"
        Mercury()
  • 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-09T17:57:59+00:00Added an answer on June 9, 2026 at 5:57 pm

    The problem is that you have:

    if mercury or mercury2 in ans:
    

    This if statement will be True if mercury evaluates to True (which it always does) or when mercury2 in ans is True.

    mercury is a non-empty string (mercury = "57.9") which will evaluate to True. For example, try bool("57.9") to see that Python always computes True for non-empty strings. If the string is empty then it will be False.

    So no matter what the user answers, your code will always say that it is correct. Here’s what you could write:

    if mercury in ans or mercury2 in ans:
    

    but it’s probably better to write (see discussion in comments below):

    if ans in [mercury, mercury2]:
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a quiz program. I have a 1-Dimensional array of correct answers from
I have a program that gets a JSON from the server using getJSON and
i have program which prints all char from char_min to char_max here is code
I have program consisting of a number of classes. I have a problem with
I have a program that I want to use google maps for. The problem
I have a MySQL Database for a basic quiz program I'm making. The questions
I have program use c and c++ language to access data from MySQL database.
I have program written with R. I can run it from the R GUI
I have program written in C. It takes 2 arguments username/password and try to
I have program that requires Python 3, but I develop Django and it uses

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.