Question: Write unit tests for this codes Python Code: def is_palindrome(s: str) -> bool: s = s.lower() s = .join(c for c in s if c.isalnum())

Write unit tests for this codes

Python Code:

def is_palindrome(s: str) -> bool:

s = s.lower()

s = "".join(c for c in s if c.isalnum())

return s == s[::-1]

if __name__ == '__main__':

s = input("Enter a string: ")

if is_palindrome(s):

print("The string is a palindrome.")

else:

print("The string is not a palindrome.")

C++ Code

#include

#include

using namespace std;

bool isPalindrome(string str) {

int len = str.length();

for (int i = 0; i < len / 2; i++) {

if (str[i] != str[len - i - 1]) {

return false;

}

}

return true;

}

int main() {

string str;

cout << "Enter a string: ";

getline(cin, str);

bool result = isPalindrome(str);

if (result) {

cout << "The string is a palindrome." << endl;

} else {

cout << "The string is not a palindrome." << endl;

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!