Ad
Code
Diff
  • def temperature_converter(temp: float, conversion='both') -> float:
        convert = {}
        convert['celsius'] = round((temp - 32) * (5 / 9) , 2)
        convert['fahrenheit'] = round((temp *  9 / 5) + 32, 2)
        convert['both'] = f"{convert['celsius']}c, {convert['fahrenheit']}f"
        
        return convert[conversion]
    • def temperature_converter(temp: float, conversion="both") -> float:
    • def temperature_converter(temp: float, conversion='both') -> float:
    • convert = {}
    • convert['celsius'] = round((temp - 32) * (5 / 9) , 2)
    • convert['fahrenheit'] = round((temp * 9 / 5) + 32, 2)
    • convert['both'] = f"{convert['celsius']}c, {convert['fahrenheit']}f"
    • celsius = round((temp - 32) * (5 / 9) , 2)
    • fahrenheit = round((temp * 9 / 5) + 32, 2)
    • both = f"to celsius: {celsius}\nto fahrenheit: {fahrenheit}"
    • return celsius if conversion == "to_celsius" else \
    • fahrenheit if conversion == "to_fahrenheit" else \
    • both
    • return convert[conversion]
Code
Diff
  • def TemperatureConverter (temp: float, conversion="both") -> float:
        match conversion:
            case "to_celsius":
                formula = round((temp - 32) * (5 / 9), 2)
            case "to_fahrenheit":
                formula = round((temp * 9 / 5) + 32, 2)
            case "both":
                formula = f"to celsius: {round((temp - 32) * (5 / 9), 2)}\nto fahrenheit: {round((temp * 9 / 5) + 32, 2)}"
        return formula
        
    
            
    • class TemperatureConverter:
    • def TemperatureConverter (temp: float, conversion="both") -> float:
    • match conversion:
    • case "to_celsius":
    • formula = round((temp - 32) * (5 / 9), 2)
    • case "to_fahrenheit":
    • formula = round((temp * 9 / 5) + 32, 2)
    • case "both":
    • formula = f"to celsius: {round((temp - 32) * (5 / 9), 2)}\nto fahrenheit: {round((temp * 9 / 5) + 32, 2)}"
    • return formula
    • def __init__(self, temp: float):
    • self.celsius = round((temp - 32) * (5 / 9), 2)
    • self.fahrenheit = round((temp * 9 / 5) + 32, 2)
    • def fahrenheit_to_celsius(self) -> float:
    • return self.celsius
    • def celsius_to_fahrenheit(self) -> float:
    • return self.fahrenheit
Code
Diff
  • import string
    def is_palindrome(s: str) -> bool:
        forward = s.lower().replace(" ", "").translate(str.maketrans('', '', string.punctuation))
        reverse = forward[::-1]
        if forward == reverse:
            return True
        else:
            return False
    • import string
    • def is_palindrome(s: str) -> bool:
    • return (True)
    • forward = s.lower().replace(" ", "").translate(str.maketrans('', '', string.punctuation))
    • reverse = forward[::-1]
    • if forward == reverse:
    • return True
    • else:
    • return False