Functions in python 3
<p>I'm struggling with functions in python 3. How can I make the below code print out the result in degrees Celsius? Is the indentation wrong, or has it to do with me not defining Celsius outside the function in the first place? Does this mean I do not have to use functions for simple tasks or is it better to do so anyway?</p>

<pre><code>print ("Welkom bij mijn Fahrenheit naar Celsius converteerprogramma!")

fahrenheit = int(input("Voer aantal graden Fahrenheit in "))

def converter_fahrenheit(fahrenheit):
    celsius = (fahrenheit - 32) * 5/9
print (fahrenheit, "graden Fahrenheit is omgerekend ","%.2f" % celsius,"graden Celsius")
</code></pre>

<p>You seem to have misunderstood how functions work. When you write something like:</p>

<pre><code>def converter_farenheit(farenheit):
    some_code
</code></pre>

<p>The code inside doesn't actually get run until you call the function by calling it later in the program. You've already called a few functions like <code>int</code> and <code>input</code> and <code>print</code> in your program, and using <code>converter_farenheit</code> looks basically the same.</p>

<p>Further, if you want to get a value back out of a function, you need it to <code>return</code> something, which passes it back out of the function allowing you to assign variables to its value, so <code>converter_farenheit</code> should really look like</p>

<pre><code>def converter_fahrenheit(fahrenheit):
    return (fahrenheit - 32) * 5/9
</code></pre>

<p>Which means you can write</p>

<pre><code>def converter_fahrenheit(fahrenheit):
    return (fahrenheit - 32) * 5/9

fahrenheit = # some code to grab input goes here
celsius = converter_farenheit(farenheit)
</code></pre>

<p>Giving <code>celsius</code> the value you expect it to. You asked whether you should avoid using functions for simple tasks, but in fact you should write as many simple functions as possible. As your programs get more complex, you'll find that lots of short, simple functions each doing a small, specific job are very easy for you to reason about and test.</p>

python