diff --git a/HexToDec.py b/HexToDec.py index 2b289400..9e54ea8a 100644 --- a/HexToDec.py +++ b/HexToDec.py @@ -7,7 +7,7 @@ def __getDecDigit(digit): if digit == digits[x]: return x -def hexToDec(hexNum): +def hex_to_Dec(hexNum): decNum = 0 power = 0 for digit in range(len(hexNum), 0, -1): diff --git a/TempConversion.py b/TempConversion.py index b8c71e54..4fb528ef 100644 --- a/TempConversion.py +++ b/TempConversion.py @@ -1,29 +1,30 @@ # Temperature Conversion Program def menu(): - print("\n1. Celsius to Fahrenheit") - print("2. Fahrenheit to Celsius") - print("3. Exit") - choice = int(input("Enter a choice: ")) - return choice - -def toCelsius(f): - return int((f - 32) / 1.8) + print("\n1. Celsius to Fahrenheit") + print("2. Fahrenheit to Celsius") + print("3. Exit") + choice = input("Enter a choice: ") + return choice + +def to_celsius(f): + return int((f - 32) / 1.8) + +def to_fahrenheit(c): + return int(c * 1.8 + 32) -def toFahrenheit(c): - return int(c * 1.8 + 32) - def main(): - choice = menu() - while choice != 3: - if choice == 1: - c = eval(input("Enter degrees Celsius: ")) - print(str(c) + "C = " + str(toFahrenheit(c)) + "F") - elif choice == 2: - f = eval(input("Enter degrees Fahrenheit: ")) - print(str(f) + "F = " + str(toCelsius(f)) + "C") - else: - print("Invalid choice.") - choice = menu() - -main() \ No newline at end of file + choice = menu() + while choice != '3': + if choice == '1': + c = float(input("Enter degrees Celsius: ")) + print(f"{c}C = {to_fahrenheit(c)}F") + elif choice == '2': + f = float(input("Enter degrees Fahrenheit: ")) + print(f"{f}F = {to_celsius(f)}C") + else: + print("Invalid choice.") + choice = menu() + +if __name__ == "__main__": + main() \ No newline at end of file