Q: If statement within a function is skipped, despite conditions being fufilled I was making a miles to km / km to miles converter and when run the converter skips over the if statement even when the conditions appear to be fulfilled, and instead executes the else statement.
Here's the code: 
"""Converts mi to km."""
print("Welcome to the converter!")
miorkm = input("Km to mi, or mi to km: ").lower
val = input("How many Km or Mi: ")

def converter(inpu2):
    """Converts the value."""
    output = 0
    if miorkm == "km":
        output = int(val) * 0.621
    else:
        output = int(val) * 1.609
    return output
print(converter(miorkm))

Any help would be appreciated!

A: Learn to use a debugger.  pdb is a simple console debugger, but there are plenty of GUI ones that are easier to use.
First, kick off the debugger in your script.
C:\>py -m pdb test.py
> c:\test.py(1)<module>()
-> """Converts mi to km."""

n executes a line and does not go into calls.  We'll advance to the first input line:
(Pdb) n
> c:\test.py(2)<module>()
-> print("Welcome to the converter!")
(Pdb) n
Welcome to the converter!
> c:\test.py(3)<module>()
-> miorkm = input("Km to mi, or mi to km: ").lower

Executing this line will prompt for miorkm:
(Pdb) n
Km to mi, or mi to km: km
> c:\test.py(4)<module>()
-> val = input("How many Km or Mi: ")

Check the value just entered:
(Pdb) miorkm
<built-in method lower of str object at 0x0000000002B65E68>

That isn't "km"!  You assigned the str.lower method to the variable.  Call the method instead with .lower().
But in case you don't notice this, keep going:
(Pdb) n
How many Km or Mi: 10
> c:\test.py(7)<module>()
-> def converter(inpu2):
(Pdb) n
> c:\test.py(15)<module>()
-> print(converter(miorkm))

Here we don't want n to execute the whole line.  We want s to step into the converter function:
(Pdb) s
--Call--
> c:\test.py(7)converter()
-> def converter(inpu2):

Now we are in the converter() function.  Look for problems...
(Pdb) s
> c:\test.py(9)converter()
-> output = 0
(Pdb) s
> c:\test.py(10)converter()
-> if miorkm == "km":
(Pdb) s
> c:\test.py(13)converter()
-> output = int(val) * 1.609

This went to the wrong line!  miorkm was supposed to be "km".  Check it:
(Pdb) miorkm
<built-in method lower of str object at 0x0000000002B65E68>

A faster way to find the problem is to note you always go to the else: statement.  Edit the code to import pdb, then set a breakpoint before the if with pdb.set_trace():
import pdb
"""Converts mi to km."""
print("Welcome to the converter!")
miorkm = input("Km to mi, or mi to km: ").lower
val = input("How many Km or Mi: ")


def converter(inpu2):
    """Converts the value."""
    output = 0
    pdb.set_trace()
    if miorkm == "km":
        output = int(val) * 0.621
    else:
        output = int(val) * 1.609
    return output
print(converter(miorkm))

Output:
Welcome to the converter!
Km to mi, or mi to km: km
How many Km or Mi: 10
> c:\users\metolone\desktop\test.py(12)converter()
-> if miorkm == "km":

After it hits the breakpoint, check the value of miorkm:
    (Pdb) miorkm
    
A final method...the easiest.  Add a print before the if:
print('miorkm =',miorkm)
if(...)

Output:
Welcome to the converter!
Km to mi, or mi to km: km
How many Km or Mi: 10
miorkm = <built-in method lower of str object at 0x000000000226B1B8>
16.09


A: .lower should be .lower(). It was returning a function, which != 'km'.
