def palindrome(string): middle = int(len(string) / 2) is_palindrome = False for i in range(0, middle): if string[i].lower() == string[-i - 1].lower(): is_palindrome = True else: is_palindrome = False return is_palindrome
using System;class Palindrome{public static bool Check(string word){for(int i = 0; i < word.Length; i++){word = word.ToUpper();if(i >= word.Length /2){break;}if(word[i] != word[word.Length - 1 - i]){return false;}}return true;}}- def palindrome(string):
- middle = int(len(string) / 2)
- is_palindrome = False
- for i in range(0, middle):
- if string[i].lower() == string[-i - 1].lower():
- is_palindrome = True
- else:
- is_palindrome = False
- return is_palindrome
test.assert_equals(palindrome('bab'), True) test.assert_equals(palindrome('aaAAaa'), True) test.assert_equals(palindrome('abcCAB'), True) test.assert_equals(palindrome('123123asdasd'), False)
namespace Solution {using NUnit.Framework;using System;// TODO: Replace examples and use TDD development by writing your own tests[TestFixture]public class SolutionTest{[Test]public void MyTest(){Assert.AreEqual(true, Palindrome.Check("MOM"));Assert.AreEqual(true, Palindrome.Check("kAyaK"));Assert.AreEqual(true, Palindrome.Check("123454321"));}}}- test.assert_equals(palindrome('bab'), True)
- test.assert_equals(palindrome('aaAAaa'), True)
- test.assert_equals(palindrome('abcCAB'), True)
- test.assert_equals(palindrome('123123asdasd'), False)