Python Forum
My first temperature converter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My first temperature converter
#1
NOTE: THIS IS A HOMEWORK, AND I AM NOT LOOKING FOR PEOPLE TO DO IT FOR ME!

Hi guys! in my programming class I am required to create a temperature converter that will be able to convert from/to Celsius, Fahrenheit and Kelvin. However, each time I try to debug my code, I always need to input the temperature type and the number two times before I can finally see my results.
Thanks for the help! (Excuse my english)

Requirements :
- First, I must first display an introduction to the program.

- After, I need to ask the user to enter the temperature choice they
wishes to enter. The choice must be validated and must accept lowercase and uppercase letters.
(String.upper)

- Finally, I need to make the user enter a temperature. Afterwards, the program must display the temperature that the user entered in the 3 different types of temperatures.
The program must aslo ask the user if they want to start over. The 'Y' and 'N'
will restart the program, while any other will let it end.

Here is the work I did according to the requirements:
def displayIntro():
    print("This programm enables you to to convert from/to Celsius, Fahrenheit and Kelvin")

def inputTempType():
    print("C - Celsius")
    print("F - Fahrenheit")
    print("K - Kelvin")
    print("Enter the type of temperature to convert: ")
    tempType = input().upper()
    return tempType

def inputTempValue():
    print("PLS enter a number: ")
    tempValue = float(input())
    return tempValue

def celToFah(cel):
    return cel * 9/5 + 32

def celToKel(cel):
    return cel + 273.15

def fahToCel(fah):
    return fah - 32 * 5/9

def fahToKel(fah):
    return fah - 32 * 5/9 + 273.15

def kelToCel(kel):
    return kel - 273.15

def kelToFah(kel):
    return kel - 273.15 * 9/5 + 32

def displayResults(cel, fah, kel):
    print("Celsius =", cel)
    print("Fahrenheit =", fah)
    print("Kelvin =", kel)
    return cel and fah and kel

def main():
    displayIntro()
    tempType = inputTempType() 
    tempValue = inputTempValue()

    continueChoice = "Y"

    while continueChoice == "Y" or continueChoice == "N":
        tempType = inputTempType()
        tempValue = inputTempValue()
    
    
        if tempType.upper() == "C":
            cel = tempValue
            fah = celToFah(cel)
            kel = celToKel(cel)
        elif tempType.upper() == "F":
            fah = tempValue
            cel = fahToCel(fah)
            kel = fahToKel(fah)
        else: #Kelvin
            kel = tempValue
            cel = kelToCel(kel)
            fah = kelToFah(kel)

        displayResults(cel, fah, kel)
        
        continueChoice = input("Would you like to continue?: Y(YES N(NO)").upper()
        if continueChoice == 'Y':
            main()
        elif continueChoice == 'N':
            break
        else:
            exit()
main()
Reply


Messages In This Thread
My first temperature converter - by TheLowEndTheory - Oct-17-2020, 07:47 PM
RE: My first temperature converter - by jefsummers - Oct-17-2020, 08:07 PM
RE: My first temperature converter - by Yoriz - Oct-17-2020, 10:41 PM
RE: My first temperature converter - by buran - Oct-18-2020, 06:53 AM
RE: My first temperature converter - by buran - Oct-18-2020, 04:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Temperature converter Help (ASAP) Edison_Weng 1 2,824 Apr-16-2018, 01:55 PM
Last Post: stranac
  how to get the highest monthly average temperature? nikhilkumar 2 7,040 Jul-25-2017, 02:33 PM
Last Post: DeaD_EyE
  Using a range and for loop - temp converter rattlerskin 5 15,726 Jan-20-2017, 09:15 PM
Last Post: sparkz_alot
  Temp Converter with Kelvin vader33 7 12,198 Oct-02-2016, 05:16 AM
Last Post: vader33

Forum Jump:

User Panel Messages

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