def testCalculation(self): self.assertEqual(palindrome(11), True) self.assertEqual(palindrome(101), True) self.assertEqual(palindrome(100), False) self.assertEqual(palindrome(212), True) self.assertEqual(palindrome(200), False) self.assertEqual(change_basis(21, 2), 10101) self.assertEqual(change_basis(21, 3), 210) self.assertEqual(change_basis(15, 3), 120) self.assertEqual(change_basis(7, 3), 21) self.assertEqual(change_basis(5, 2), 101)
def main(): #function to obtain the smallest base in which the number is palindrome from 1 to n n_input = input('Enter the last number to analize : ') try: n = int(n_input) print('number', '|', 'smallest base in which the number is a palindrome') for number in range(1, n + 1): count = 2 nume = change_basis(number, count) while not palindrome(nume): count += 1 nume = change_basis(number, count) width = len('number') print("{0:{width}{type}} |{1:{width}{type}}".format( number, count, width=width, type='d')) except ValueError: print('Not integer value')
def test_if_a_non_palindrome_returns_false(self): example = 'abcd' expected_result = False self.assertEqual(palindrome(example), expected_result)
def test_if_a_palindrome_returns_true(self): example = 'abcba' expected_result = True self.assertEqual(palindrome(example), expected_result)
from functions import triangle, reverse, upper_lower, palindrome #Task_1 triangle(10,14) print(triangle.__doc__) print(triangle.__annotations__) #Task_2 user = input("Print somethong and I\'ll print it in reverse! \n") reverse(user) print(reverse.__doc__) print(reverse.__annotations__) #Task_3 user = input("Say something and I\'ll calculate the number of\nupper case and lower case letters! \n") upper_lower(user) print(upper_lower.__doc__) print(upper_lower.__annotations__) #Task_4 user = input("Say somethong and I\'ll check if that\'s palindrome or not! \n") palindrome(user) print(palindrome.__doc__) print(palindrome.__annotations__)