Saturday 2 September 2017

python program

class Palindrome:

    @staticmethod
    def is_palindrome(word):
        return word == word[::-1]
      

print(Palindrome.is_palindrome('Deleveled'))
print(Palindrome.is_palindrome('poop'))

==============
path = Path('/a/b/c/d') path.cd('../x') print(path.current_path) #should display '/a/b/c/x'.

class Path:
    def __init__(self, path):
        self.current_path = path

    def cd(self, new_path):
        new_path_list = new_path.split('/')
        for item in new_path_list:
            if item == '':
                self.current_path = '/'
            elif item == '..':
                self.current_path = self.current_path[:-2]
            else:
                self.current_path = self.current_path + '/' + item


path = Path('/a/b/c/d')
path.cd('../x')
print(path.current_path)

No comments:

Post a Comment