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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

幾乎相同的功能,但不起作用?

幾乎相同的功能,但不起作用?

胡說叔叔 2021-06-14 12:31:50
我嘗試了一些使用 python 的東西,雖然encrypt()函數(shù)工作正常,但decrypt()函數(shù)沒有給我任何輸出,甚至沒有錯誤:(我的代碼:import osabc=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', ' ', '.', ',', '1', '2', '3', '4',   '5', '6', '7', '8', '9', '0', '+', '-', ':', "'"]mixed=abc[::-1]os.system("clear")def menu():    print "-----------"    print "[1] Encrypt"    print "[2] Decrypt"    print "-----------"    if input(">>> ")==1:        encrypt()    elif input(">>> ")==2:        decrypt()def encrypt():    os.system('clear')    text=raw_input(">>> ").lower()    text=list(text)    textnew=text    for i in range(len(text)):        textnew[i]=mixed[abc.index(text[i])]    print ''.join(textnew)    menu()def decrypt():    os.system('clear')    text=raw_input(">>> ").lower()    text=list(text)    textnew=text    for i in range(len(text)):        textnew[i]=abc[mixed.index(text[i])]    print ''.join(textnew)    menu()menu()
查看完整描述

2 回答

?
三國紛爭

TA貢獻1804條經(jīng)驗 獲得超7個贊

if input(">>> ")==1:

    encrypt()

elif input(">>> ")==2:

    decrypt()

您正在閱讀elif. 這就是為什么第一個命令似乎被忽略的原因。順便說一句,input在 Python 2 中是不安全的。你應(yīng)該堅持使用raw_input(它只返回一個字符串而不嘗試評估它)。


command = raw_input(">>> ")

if command=="1":

    encrypt()

elif command=="2":

    decrypt()


查看完整回答
反對 回復(fù) 2021-06-16
?
RISEBY

TA貢獻1856條經(jīng)驗 獲得超5個贊

這里有一些建議:

  • 使用 raw_input

  • 不要重復(fù)自己 - 不需要 4 個打印語句

  • 您的函數(shù)打印相同的提示。這讓用戶感到困惑。至少添加一些關(guān)于正在發(fā)生的事情的指示

  • 而不是遞歸調(diào)用main()(并最終達到限制可以在堆棧上調(diào)用多少函數(shù)),makemain()有一個每次調(diào)用您的函數(shù)的循環(huán)。

  • 養(yǎng)成編寫的習(xí)慣,if __name__ = '__main__':因為當(dāng)您開始編寫 Python 模塊時,您不希望腳本在導(dǎo)入時運行所有內(nèi)容,而只是向調(diào)用腳本提供函數(shù)。

  • 換行 80 個字符

編輯的代碼:

import os

abc=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 

     'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', ' ', '.', 

     ',', '1', '2', '3', '4',   '5', '6', '7', '8', '9', '0', '+', '-', 

     ':', "'"]

mixed=abc[::-1]

os.system("clear")


def menu():

    header = '\n'.join(["-----------","[1] Encrypt",

                        "[2] Decrypt","-----------"])

    while True:

        print header

        user_input = raw_input(">>> ")

        # print "DEBUG:user input:",user_input

        if user_input == '1':

            encrypt()

        elif user_input == '2':

            decrypt()

        elif user_input == 'q':

            exit()

        else:

            print("Bad input")


def get_input():

    os.system('clear')

    print "Encrypt"

    text=raw_input(">>> ").lower()

    return list(text)



def encrypt():

    text = get_text()

    textnew=text

    for i in range(len(text)):

        textnew[i]=mixed[abc.index(text[i])]

    print ''.join(textnew)


def decrypt():

    text = get_input()

    textnew=text

    for i in range(len(text)):

        textnew[i]=abc[mixed.index(text[i])]

    print ''.join(textnew)


if __name__ = '__main__':    

    menu()


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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