uv333
uv333

Reputation: 1

Return of a false value

The purpose of the following function is to iterate through foot_bones looking for a match of the string argument in search2.

The input will be taken from the user. The output is

it is not a footbone

no matter what the input is.

def foot(search2, foot_bones = ["calcaneus", "talus", "cuboid", "navicular","lateral cuneiform","intermediate cuneiform", "medial cuneiform"]):
    for dk in foot_bones:
        if search2.lower() == dk.lower:
            return True
            break
search = input("Enter the bone name")
if foot(search2=search):
    print("the entered bone is a footbone")
else: 
    print("it is not a footbone")

Upvotes: 0

Views: 34

Answers (2)

Elpedio Jr. Adoptante
Elpedio Jr. Adoptante

Reputation: 101

you can also shorten your code by doing...

def foot(...):
    return search2.lower() in foot_bones

Upvotes: 0

B. Go
B. Go

Reputation: 1424

You forgot the parentheses after dk.lower, therefore you compare search2.lower() to the lower method of dk instead of the lowercase foot bone.

Change that line to:

if search2.lower() == dk.lower():

Upvotes: 4

Related Questions