第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何用隨機(jī)字母添加每隔一個(gè)字母?

如何用隨機(jī)字母添加每隔一個(gè)字母?

達(dá)令說 2021-10-05 16:16:24
我正在嘗試使用類和函數(shù)向字符串中每兩個(gè)字母添加一個(gè)隨機(jī)字母class Encryption():    def __init__(self,seed):        # Set a random seed and a self.seed attribute        self.seed = seed        # Create an empty string attribute to hold the encrypted phrase        self.encrypted_phrase = ''        # Use the string and random libraries to create two attributes        # One is the correct alphabet, another is a shuffled alphabet:        self.correct_alphabet = list(string.ascii_lowercase)        self.shuffeled_alphabet = random.sample(correct_alphabet, seed)    def encryption(self,message):        appended_message = list(message)               for let in list(range(0, len(message), 2)):            if let in self.correct_alphabet:                appended_message.append(self.shuffeled_alphabet)        return appended_message所以如果我這樣做e2 = Encryption(3)e2.encryption(hello)它失敗并顯示以下消息NameError                                 Traceback (most recent call last)<ipython-input-24-505d8a880fb2> in <module>----> 1 e2.encryption(message=hello)NameError: name 'hello' is not defined我究竟做錯(cuò)了什么?
查看完整描述

2 回答

?
ibeautiful

TA貢獻(xiàn)1993條經(jīng)驗(yàn) 獲得超6個(gè)贊

hello 需要是一個(gè)字符串,因?yàn)樗皇且粋€(gè)變量。


嘗試e2.encryption("hello")或類似的東西。


所以你的完整代碼示例是:


e2 = Encryption(3)

e2.encryption("hello")


查看完整回答
反對 回復(fù) 2021-10-05
  • 2 回答
  • 0 關(guān)注
  • 209 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號