ps6.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:MITx-6.00.1x-Introduction-to-Computer-Science-and-Programming-Using-Python 作者: xianglol 项目源码 文件源码
def apply_shift(self, shift):
        '''
        Applies the Caesar Cipher to self.message_text with the input shift.
        Creates a new string that is self.message_text shifted down the
        alphabet by some number of characters determined by the input shift        

        shift (integer): the shift with which to encrypt the message.
        0 <= shift < 26

        Returns: the message text (string) in which every character is shifted
             down the alphabet by the input shift
        '''
        letters_all = string.ascii_lowercase + string.ascii_uppercase

        shifted_txt = ''
        shift_dic = self.build_shift_dict(shift)

        for e in self.message_text:
            if e in letters_all:
                e = shift_dic[e]
            shifted_txt += e
        return shifted_txt
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号