Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help tempertaure
#1
Help I have been at this for days and I do not understand what I am doing wrong.  the script will not run. :huh:  also I do not have any errors and when I try and run it, it shuts down immeditly.  This is my first time doing this.
#The program will ask the user to select from a menu.

input("Temperature Convertor")

def menu():  
  print("n\1. Celsius Temperature to Fahrenheit Temperature")
  print("2. Fahrenheit Temperature to Celsius Temperature")
  print("3. Exit")
  choice = raw_int(input(" Please Enter a Selection: "))
  return choice
  
#Once a selection is made from the menu, the user will be able to covert #Celsius and Fahreheit temperature.

#The coversion formula for Fahrenheit to Celsius is C= ((F-32) * 5/9)

def toCelsius (F) :
  return int((F - 32) / (5/9) )
 
#The coversion formula for Celsius to Fahrenheit that is being used is F = ((9/5 * C )+ 32).

def toFahrenheit (C) :
  return int((C * 9/5) + 32 )
  
#The program will ask the user to enter a temperature in Celsius or Fahreheit 
#depending on what the user selected and then display the 
#temperature converted to Fahreheit or Celsius.
 
def main() :
  choice = Menu ()
  while choice != 3 :
                if choice == 1 :
                        # convert C to F
                        C = float(input( " Please enter degrees in Celsius that you would like to convert: "))
                        Print (str (C) + " C = " + str(toFahrenheit (C)) + "F" )
                elif choice == 2 :
                        # convert F to C
                        F = float(input( " Please enter degrees in Fahrenheit that you would like to convert: "))
                        print (str (F) + " F = " + str(toCelsius (F)) + "F" )
                else:  
                        print ( " Invalid Entry " )
                choice = Menu ()
input("\n\nPress the return key to exit.")
Reply
#2
Why have you written (if you wrote it) so much code that doesn't run?

You haven't even attempted to call any of the functions you wrote so I'm not really sure what you expect to happen.
There are a lot of little tiny problems.  raw_int doesn't exist; case mistakes (Menu vs menu).

Call your main function and try to correct some of the minor mistakes.  Then please post your error.  Your current code doesn't show an error because you never call main.
Reply
#3
It runs with some tiny changes:
#python3
def menu():
    print("1. Celsius Temperature to Fahrenheit Temperature")
    print("2. Fahrenheit Temperature to Celsius Temperature")
    print("3. Exit")
    return int(input(" Please Enter a Selection: "))

def toCelsius(F) :
    return int((F - 32) / (9/5))

def toFahrenheit(C) :
    return int((C * (9/5)) + 32)

def main() :
    while True:
        choice = menu()
        if choice == 1 :
            C = float(input( " Please enter degrees in Celsius that you would like to convert: "))
            print(str(C) + "C = " + str(toFahrenheit(C)) + "F\n\n")
        elif choice == 2 :
            F = float(input( " Please enter degrees in Fahrenheit that you would like to convert: "))
            print(str(F) + "F = " + str(toCelsius(F)) + "C\n\n" )
        else:
            break

main()
Reply
#4
All of your code is contained within main()... but you never call main(). So there's no error, because you never try to do anything.
Reply
#5
You are right the OP has no main-function.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020