Your conversion functions have two notable things:
You're printing the result directly. Don't do this. For toy programs like this, this is ok doing so doesn't create problems. In the real world though, you don't just print data to the screen, you use data. With how you have it now, the caller can't actually use the converted value for anything. What if you wanted to send the raw data over the internet or save it to a file?
You're putting an empty
returnat the end. This is redundant though and unnecessary.Noneis automatically returned at the end anyways if noreturnis met, which is equivalent to what you're doing.
I would have the functions return the converted value, and print it at the call site:
def value_input(selection):
value = input('''\nPlease enter the temperature you
want to convert: ''')
try:
value = float(value)
except ValueError:
print('That is not a number!\n')
else:
is_celsius = selection == 'c' # Save if we're converting to Celsius or not
is_celsius = selection == 'c'
new_value = convert_c2f(value) if is_celsius else convert_f2c(value)
unit_str = "C" if is_celsius else "F"
print(f'The answer is: {new_value}°{unit_str}')
def convert_c2f(value):
return (value * (9 / 5)) + 32
def convert_f2c(value):
return (value - 32) * (5 / 9)
I decided to reduce the printing down to a single call to print and just decide what data will be printed ahead of time. This is personal style though. I get an odd thrill out of reducing duplication. Do whatever you feel is more readable.