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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:31:21+00:00 2026-06-16T04:31:21+00:00

I think the best way to explain this will be to post my code,

  • 0

I think the best way to explain this will be to post my code, and the results from the shell. I’m new to Python (using 3.3), and coding in general, so I’m sure I’m just missing something very simple.

Here’s my code:

def menu():
    global temp
    global temp_num

    temp = input('Enter a temperature to convert:\n (ex. 32F) ->  ')
    temp_select = temp[-1]
    temp_num = int(temp[:-1])

    if temp_select == 'F' or 'f':
        return Fahr()
    elif temp_select == 'C' or 'c':
        return Cels()
    elif temp_select == 'K' or 'k':
        return Kelv()
    else:
        print('Please make a valid selection')
        menu()


def Fahr():
    ''' Converts selected temperature from Fahrenheit to Celsius, Kelvin, or both.'''

    selection = input('Convert to (C)elsius, (K)elvin, or (B)oth? -> ')
    to_cels = round((5/9) * (temp_num - 32), 1)
    to_kelv = round(5/9 * (temp_num - 32) + 273, 1)

    if selection == 'C' or 'c':
        print(temp_num, 'degrees Fahrenheit =', to_cels, 'degrees Celsius.\n')
        exitapp()
    elif selection == 'K' or 'k':
        print(temp_num, 'degrees Fahrenheit =', to_kelv, 'degrees Kelvin.\n')
        exitapp()
    elif selection == 'B' or 'b':
        print(temp_num, 'degrees Fahrenheit =', to_cels, 'degrees Celsius and', to_kelv, 'degrees Kelvin.\n')
        exitapp()
    else:
        print('Please make a valid selection')
        Fahr()

I have 2 other functions for Celsius and Kelvin. You’ll see the problem with my results in shell.

Here is what I get:

Enter a temperature to convert:
 (ex. 32F) ->  32C
Convert to (C)elsius, (K)elvin, or (B)oth? -> b
32 degrees Fahrenheit = 0.0 degrees Celsius.

Exit the program?
 Enter "y" or "n":

Without fail it always converts from Fahrenheit to Celsius. Every time.

  • 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-16T04:31:22+00:00Added an answer on June 16, 2026 at 4:31 am

    You can’t abbreviate conditions like you have done. This:

    if temp_select == 'F' or 'f':
        return Fahr()
    

    Is the same as this:

    if temp_select == 'F':
        return Fahr()
    if 'f':
        return Fahr()
    

    Each side of or and and are evaluated independently, and 'f' by itself is always true. You need to use full phrases for each condition.

    if temp_select == 'F' or temp_select == 'f':
        return Fahr()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The best way I think to explain this is to tell you what my
I think the best way to approach this is jump straight in and explain
I think this may not be possible, will try and explain as best as
I'm a little stumped on this one. I think the best way to ask
The best way I can think of to ask this is by example... In
This is the best way I can think of phrasing this question, given this
I'm a .htaccess nOOb, but I think this is the best way to do
Could someone explain the best way to achieve the following, I think it's a
Best way to describe this is explain the situation. Imagine I have a factory
I think the best way to explain my question is with a short (generic)

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.