[Python] positional argument for a python function

Discussão em 'Python' iniciado por Stack, Agosto 20, 2025.

  1. Stack

    Stack Membro Participativo

    def is_palindrome(teststr):
    teststr = str(teststr)
    for item in teststr:
    if str.isalnum(item):
    continue
    else:
    teststr.replace(item,'')
    teststr = teststr.lower()

    if teststr != teststr[::-1]:
    return False
    else:
    return True


    total = 0
    test_words = ["Hello World!","Radar","Mama?","Madam, I'm Adam.",
    "Race car!"]

    for word in test_words:
    if is_palindrome(word):
    total = total + 1

    print (str(total))



    TypeError: is_palindrome() missing 1 required positional argument: 'teststr'

    Not sure what it wants saw a similar question involving a dictionary but didn't see a solution

    Continue reading...

Compartilhe esta Página