Some points and improvement.
Do not use
Here the function with docstring better name and f-string(Python 3.6).
Here a test.
The loop range work like this
Do not use
eval()
,convert to int()
or float()
when needed.Here the function with docstring better name and f-string(Python 3.6).
# converter.py def temp_convert(): '''A program to convert Celsius temps to Fahrenheit''' celsius = float(input("what is the celsius temperature? ")) fahrenheit = 9/5 * celsius + 32 return(f'{celsius}°C in Celsius is {fahrenheit}°F in Fahrenheit') if __name__ == '__main__': print(temp_convert())With docstring so do also
help()
work.Here a test.
E:\1py_div\div_code λ ptpython >>> import converter >>> help(converter) Help on module converter: NAME converter - # converter.py FUNCTIONS temp_convert() A program to convert Celsius temps to Fahrenheit FILE e:\1py_div\div_code\converter.py # Run >>> print(converter.temp_convert()) what is the celsius temperature? 20 20.0°C in Celsius is 68.0°F in FahrenheitIt's not so much change to turn this into some kind of table,so it's easier to do it rather than give several hints.
The loop range work like this
range(start, stop, step)
.# temp_table.py def temp_convert(start_cel, stop_cel, step_temp): '''A program to convert Celsius temps to Fahrenheit''' for celsius in range(start_cel, stop_cel, step_temp): fahrenheit = 9/5 * celsius + 32 print(f'{celsius}°C --> {fahrenheit}°F') if __name__ == '__main__': start_cel = 0 stop_cel = 110 step_temp = 10 temp_convert(start_cel, stop_cel, step_temp)
Output:0°C --> 32.0°F
10°C --> 50.0°F
20°C --> 68.0°F
30°C --> 86.0°F
40°C --> 104.0°F
50°C --> 122.0°F
60°C --> 140.0°F
70°C --> 158.0°F
80°C --> 176.0°F
90°C --> 194.0°F
100°C --> 212.0°F