Skip to content

Instantly share code, notes, and snippets.

@AnisahTiaraPratiwi
Created March 22, 2021 08:15
Show Gist options
  • Save AnisahTiaraPratiwi/7cb4451ceeed9607e19ffd8756051579 to your computer and use it in GitHub Desktop.
Save AnisahTiaraPratiwi/7cb4451ceeed9607e19ffd8756051579 to your computer and use it in GitHub Desktop.
The is_palindrome function checks if a string is a palindrome. A palindrome is a string that can be equally read from left to right or right to left, omitting blank spaces, and ignoring capitalization. Examples of palindromes are words like kayak and radar, and phrases like "Never Odd or Even". Fill in the blanks in this function to return True …
def is_palindrome(input_string):
# We'll create two strings, to compare them
new_string = ""
reverse_string = ""
# Traverse through each letter of the input string
for string in input_string.lower():
# Add any non-blank letters to the
# end of one string, and to the front
# of the other string.
if string.replace(" ",""):
new_string = string + new_string
reverse_string = string + reverse_string
# Compare the strings
if new_string[::-1]==reverse_string:
return True
return False
print(is_palindrome("Never Odd or Even")) # Should be True
print(is_palindrome("abc")) # Should be False
print(is_palindrome("kayak")) # Should be True
@Sushil2k4
Copy link

This one worked for me
👇🏻

def is_palindrome(input_string):
    # Two variables are initialized as string date types using empty 
    # quotes: "reverse_string" to hold the "input_string" in reverse
    # order and "new_string" to hold the "input_string" minus the 
    # spaces between words, if any are found.
    new_string = ""
    reverse_string = ""

    # Complete the for loop to iterate through each letter of the
    # "input_string"
    for letter in input_string:

        # The if-statement checks if the "letter" is not a space.
        if letter != " ":

            # If True, add the "letter" to the end of "new_string" and
            # to the front of "reverse_string". If False (if a space
            # is detected), no action is needed. Exit the if-block.
            new_string = new_string + letter.lower()
            reverse_string = letter.lower() + reverse_string

    # Complete the if-statement to compare the "new_string" to the
    # "reverse_string". Remember that Python is case-sensitive when
    # creating the string comparison code. 
    if new_string ==  reverse_string:

        # If True, the "input_string" contains a palindrome.
        return True
		
    # Otherwise, return False.
    return False


print(is_palindrome("Never Odd or Even")) # Should be True
print(is_palindrome("abc")) # Should be False
print(is_palindrome("kayak")) # Should be True

@Dyprof
Copy link

Dyprof commented Jun 25, 2025

If a valid email is known to have a mix of characters and numbers and then ends with @edibrige.ng, e.g nnebaba123@edubridge.ng.
Write a functon named is_valid_email that accepts an email as an input argument and then check if the email is valid based on the condition above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment