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

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

如何格式化停止密碼程序python的輸出

如何格式化停止密碼程序python的輸出

qq_笑_17 2022-09-06 15:51:58
我正在嘗試制作一個(gè)簡單的Stoper密碼,并讓它主要按照我想要的方式工作。除了,我只想移動(dòng)郵件中大寫的字母,并保持小寫字母不變。例如,如果消息是“HeLLo”,程序應(yīng)該只移動(dòng)“H LL”并保持“e o”相同。如下所示。電流輸出:Message: HeLLoShift: 1IFMMP所需輸出:Message: HeLLoShift: 1IeMMo代碼:plain_text = input("Message: ")shift = int(input("Shift: "))def caesar(plain_text, shift):   cipher_text = ""  for ch in plain_text:    if plain_text.lower():      plain_text = plain_text    if ch.isalpha():      final_letter = chr((ord(ch) + shift - ord('A')) % 26 + ord('A'))      cipher_text += final_letter    else:      cipher_text += ch  print(cipher_text)  return cipher_textcaesar(plain_text, shift)
查看完整描述

2 回答

?
慕哥9229398

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

您可以添加條件來檢查該字符是否為小寫字符,并僅在它不是小寫字符時(shí)才對(duì)其進(jìn)行加密。ch != ch.lower()


plain_text = input("Message: ")

shift = int(input("Shift: "))


def caesar(plain_text, shift): 

  cipher_text = ""

  for ch in plain_text:

    if ch.isalpha() and ch != ch.lower():

      final_letter = chr((ord(ch) + shift - ord('A')) % 26 + ord('A'))

      cipher_text += final_letter

    else:

      cipher_text += ch

  print(cipher_text)

  return cipher_text


caesar(plain_text, shift)


查看完整回答
反對(duì) 回復(fù) 2022-09-06
?
墨色風(fēng)雨

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

我認(rèn)為你需要:


def caesar(plain_text, shift):

    return "".join([chr(ord(i)+shift) if i.isupper() else i for i in plain_text])


caesar(plain_text, shift)


查看完整回答
反對(duì) 回復(fù) 2022-09-06
  • 2 回答
  • 0 關(guān)注
  • 116 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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