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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:08:08+00:00 2026-06-18T20:08:08+00:00

The code is written in python 3.3 and only works for the first if

  • 0

The code is written in python 3.3 and only works for the first if statement, not acknowledging the other elif statements even if the if statement is wrong.

calccircle()

What data do you know? radius

Enter Diameter def calccircle():
      x = input("What data do you know? ")
      if x == "Diameter" or "diameter":
          a = int(input("Enter Diameter "))
          print("Circumference is", a * math.pi)
          print("Area is", math.pi * math.pow(a/2,2))
          print("Radius is:",a/2)
      elif x == "Radius" or "radius":
          b = input("Enter radius: ")
          print("Circumference is", b * 2 * math.pi)
          print("Area is", math.pi * math.pow(b,2))
          print("Diameter is", b * 2)
      elif x == "area" or "Area":
          c = input("Enter area: ")
          print("Circumference is", ((math.sqrt(c))/math.pi) * b * 2 * math.pi)
          print("Diameter is", math.sqrt(c) * math.pi * 2)
          print("Radius is", math.sqrt(c) * math.pi)
      elif x == "circumference" or "Circumference":
          d = input("Enter Circumference: ")
          print("Area is", math.pi * math.pow(d/math.pi,2))
          print("Diameter is", d/math.pi * 2)
          print("Radius is", d/math.pi)

It displays the input(“Enter diameter: “) and doesn’t pay attention to what I write or the if statements.

calccircle()
What data do you know? radius
Enter Diameter

Notice I wrote radius, and the input(“Enter radius: “) is supposed to run, but it doesn’t. Please help.

  • 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-18T20:08:09+00:00Added an answer on June 18, 2026 at 8:08 pm

    Your problem is this:

     if x == "Diameter" or "diameter":
    

    looks to python like:

     if (x == "Diameter") or "diameter":
    

    which, when x != "Diameter", is like:

    if "diameter":
    

    which will always go through.

    Python treats False, None, "", [], {}, ... and the like as False in the context of if statements (or if you call bool on them, or various other places), and most everything else as True. This is often handy, but can combine with a slight confusion about the or statement to make lots of people not used to Python make this mistake.

    Instead, do one of these:

    if x == "Diameter" or x == "diameter":  # most direct translation
    if x in {"Diameter", "diameter"}:  # very slightly faster, a little less typing
    if x.lower() == "diameter":  # also allows DIAmeter, etc
    

    It’s also worth noting that if you wrote something like

    if x == ("Diameter" or "diameter"):
    

    this would be the same as

    if x == "Diameter":
    

    since "Diameter" or "diameter" sees that "Diameter" is Trueish, and so returns that.

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

Sidebar

Related Questions

I would like to use some code written in python (it uses built in
I've been trying to validate my code to calculate Mahalanobis distance written in Python
I have written a few lines of code in Python to see if I
I have a larger code running in Linux, written in c++ (c++11) and python
I have written a code in Python to create a transition probability matrix from
Say I have code written in python that analyzes files on my computer and
I'm new to Python, and I've only written a couple programs. Here's a recent
I wrote a game with HTML5. Locally, it only works if I run: python
Basically I have a FileExplorer class written in Python 2.6. It works great, I
I've written my code to target Python 2.6.5, but I now need to run

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.