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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:46:17+00:00 2026-06-05T15:46:17+00:00

so i am making a temp converter and i just cant get it to

  • 0

so i am making a temp converter and i just cant get it to the calc for Fahrenheit to Celsius. It works to go from Celsius to Fahrenheit but it wont convert the other way. I am not sure what problem is causing this i have tried the intvars and stringvars but none seem to fix this problem and i have also tried the diff if statements but its just cant convert from fah to cel. Could someone please help me and tell me whats wrong. Here is what i have:

from Tkinter import*


def convert():
    celTemp = celTempVar.get()
    fahTemp = fahTempVar.get()



    if celTempVar.get() != 0.0:
        celToFah = (celTemp *  9/5 + 32)
        print celToFah
        fahTempVar.set(celToFah)

    elif fahTempVar.get() != 0.0:
        fahToCel = ((fahTemp - 32) * (5/9))
        print fahToCel
        celTempVar.set(fahToCel)



def reset():
    top = Toplevel(padx=50, pady=50)
    top.grid()
    message = Label(top, text = "Reset Complete")
    button = Button(top, text="OK", command=top.destroy)

    message.grid(row = 0, padx = 5, pady = 5)
    button.grid(row = 1, ipadx = 10, ipady = 10, padx = 5, pady = 5)

    fahTempVar.set(int(0))
    celTempVar.set(int(0))





###MAIN###
root = Tk()
root.title("Temperature Converter")
mainframe = Frame(root)
mainframe.grid()

celTempVar = IntVar()
celTempVar.set(int(0))
fahTempVar = IntVar()
fahTempVar.set(int(0))


titleLabel = Label (mainframe, text = "Celcius/Fahrenheit Temperature", font = ("Arial", 20, "bold"), justify = CENTER)
titleLabel.grid(row = 1, column = 1, columnspan = 3, pady = 10, padx = 20)

celLabel = Label (mainframe, text = "Celcius: ", font = ("Arial", 16), fg = "red")
celLabel.grid(row = 2, column = 1, pady = 10, sticky = NW)

fahLabel = Label (mainframe, text = "Fahrenheit: ", font = ("Arial", 16), fg = "blue")
fahLabel.grid(row = 3, column = 1, pady = 10, sticky = NW)

celEntry = Entry (mainframe, width = 10, bd = 5, textvariable = celTempVar)
celEntry.grid(row = 2, column = 1, pady = 10, sticky = NW, padx = 125 )


fahEntry = Entry (mainframe, width = 10, bd = 5, textvariable = fahTempVar)
fahEntry.grid(row = 3, column = 1, pady = 10, sticky = NW, padx = 125 )

convertButton =Button (mainframe, text = "Convert", font = ("Arial", 8, "bold"), relief = RAISED, bd=5, justify = CENTER, highlightbackground = "red", overrelief = GROOVE, activebackground = "green", activeforeground="blue", command = convert)
convertButton.grid(row = 4, column = 1, ipady = 8, ipadx = 12, pady = 5, sticky = NW, padx = 55)

resetButton = Button (mainframe, text = "Reset", font = ("Arial", 8, "bold"), relief = RAISED, bd=5, justify = CENTER, highlightbackground = "red", overrelief = GROOVE, activebackground = "green", activeforeground="blue", command = reset)
resetButton.grid(row = 5, column = 1,ipady = 8, ipadx = 12, pady = 5, sticky = NW)

root.mainloop()
  • 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-05T15:46:19+00:00Added an answer on June 5, 2026 at 3:46 pm

    The problem is this line:

    fahToCel = ((fahTemp - 32) * (5/9))
    

    The issue is that the 5/9 is computed using integer division (because both inputs to it are integers); it happens to be equal to 0, which isn’t what you want here! There’s a whole bunch of possible fixes, but the simplest is to just use 5.0/9.0 which is unambiguously dealing with floating-point division. (You might as well change the opposite direction too, even if just for clarity. Yes, it is currently working but this is because the multiply — which has a float input of celTemp — is processed before the divide there.)

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

Sidebar

Related Questions

If I execute cmd /c %programfiles%\mycode\md5sums.exe %temp% it works just fine. But when I
I'm making a notepad-like program. To get the text from a file I read
I'm making a temporary table which is a summary of data from two other
Making a new site but something is happening to it in IE8. The social
Making a new site but something is happening to it in IE. I've purchased
I have an array and I am making a hash instance from it. For
I'm sure I'm making some kind of silly mistake here, but when converting a
So I am making a class which handles my file uploading from a form.
There are plenty of great answers to questions about making a standalone executable, but
I'm making a simple fifo style character module. I'm struggling to get it to

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.