Oct-17-2020, 07:47 PM
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:
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()