如何使用不同的文件,并使其在其他文件中使用??(Python)

2024-04-24 19:53:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python新手,我试图让用户通过加密或解密的文件输入他们的消息。我试着研究如何做这件事,但不知该怎么办!在

这是我的代码:

print("Welcome! Would you like to encrypt a message or decrypt message ? ")
print("1. encrypt message")
print("2. decrypt message")
print("3. exit programme")
print("Selection 1 or 2 or 3? Please enter your selection:")

while True:
    choice = int(input())
    if choice == 1:
        print("Please enter your file that you want to be encrypted:")
    elif choice == 2:
        print("Please enter your file that you want to be decrypted:")
    else:
        exit

Tags: ortoyoumessageyourthatexitfile
1条回答
网友
1楼 · 发布于 2024-04-24 19:53:25

这看起来很像GCSE AQA计算机科学传统场景任务。。。有趣的是。在

你开始的方式表明你对编程是新手。其中一个菜单选项是退出程序,如果条件为真,它将运行while循环。因为你永远不会写的是真的。因此,它永远运行,所以退出不是一个选择。在

这就是菜单的工作原理


#this could be your menu loop

    def menu():
        print("1] Encrypt text")
        print("2] Decrypt text")
        print("3] exit program")
        choice = input("Choice: ") #There is no point Turing it into an integer, it      just allows for the program to break is someone types anything other than a number
        if choice == "1":
            encryption()
            menu()
        elif choice == "2":
            decryption()
            menu()
        elif choice == "3"
            print("Exiting...")
        else:
            print("Invalid selection")
            menu()  

实际的加密/解密需要从文件中获取文本,然后添加一个通过从随机密钥中获取值生成的偏移量(如果这是您课程的一部分)

实际的节目太长了,不能放在这里解释。而陈述其实是最基本的东西。也不知道这是如何工作,使它不可能做的书面部分得分方式更多的分数。在

我现在也在读普通中等教育证书,很多人都在努力学习,因为这类课程的教授范围不够广,这是一种遗憾。在

相关问题 更多 >