如何用Python语言回答这个问题? [英] How do I answer this question in Python language?

查看:95
本文介绍了如何用Python语言回答这个问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是编程新手,我想知道是否有人可以帮我解决这个问题?





公司我想通过电话传输数据,但担心手机可能会被窃听。它的所有数据都以四位整数形式传输。它要求你编写一个程序来加密其数据,以便更安全地传输数据。

加密过程如下:

将每个数字替换为(该数字的总和加上7)模数10.然后将第一个数字与第三个数字交换,并将第二个数字与第四个数字交换。获得的整数将是加密的整数。

您要通过编写名为encrypt的函数来实现此加密,该函数将接受一个四位整数作为参数,并将加密的整数返回给调用者。写一个名为decrypt的另一个函数,它接受一个加密的四位整数并对其进行解密以形成原始数字。

实现两个方法中的方法./ $


程序/模块名为security.py。在该模块中包括将提示用户输入原始数据并调用加密功能进行加密的主要功能,并通过传递加密整数来调用解密功能进行解密。在这两种情况下,您都要以4位数格式显示结果。



我尝试过:



def main():



IntInput = int(输入(在此处输入一个整数:))< br $>


a = IntInput / 1000

b =(IntInput / 100)%10

c =(IntInput / 10)% 10

d = IntInput%10

Hello, I'm new to programming and I was wondering if anyone can help me with this question?


A company wants to transmit data over the telephone, but it is concerned that its phones may be tapped. All of its data are transmitted as four-digit integers. It has asked you to write a program that will encrypt its data so that the data may be transmitted more securely.
The encryption process proceeds as follows:
Replace each digit by (the sum of that digit plus 7) modulus 10. Then swap the first digit with the third, and swap the second digit with the fourth. The integer obtained will be the encrypted integer.
You are to implement this encryption by writing a function named encrypt that will accepts a four-digit integer as parameter and return the encrypted integer to the caller.

Write another function named decrypt that accepts an encrypted four-digit integer and decrypts it to form the original number.
Implement both the methods in a program/module named security.py. Include in this module the main function that will prompt user for original data and invoke the encrypt function for encryption, and invoke the decrypt function for decryption by passing the encrypted integer. In both cases, you are to display the result, in exactly 4-digit format.

What I have tried:

def main():

IntInput = int(input("Enter an integer number here: "))

a = IntInput / 1000
b = ( IntInput / 100 ) % 10
c = ( IntInput / 10 ) % 10
d = IntInput % 10

推荐答案

我们不做你的功课:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



阅读说明,并考虑它们是什么告诉你这样做:目前你似乎已经忽略了大部分......

亲自尝试一下,你可能会发现它并不像你想象的那么难!



如果您遇到特定问题,请询问相关问题,我们会尽力提供帮助。但我们不打算为你做这一切!
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Read the instructions, and think about what they are telling you to do: at the moment you seem to have ignored most of them ...
Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!


你需要定义两个函数:

1. encrypt - 接受一个整数,转换它如你的问题所述,并返回加密值。

2.解密 - 这颠倒了上述过程。



所以你的程序将会看起来像:

You need to define two functions:
1. encrypt - which accepts an integer, converts it as described in your question, and returns the encrypted value.
2. decrypt - which reverses the above process.

So your program will look something like:
def encrypt(self, number):
    # add the encrypting code here

def decrypt(self, number):
    # add the decrypting code here

    # start of main function

while True:
    number = int(input("Please enter a number greater than 999: "))
    if number < 1000:
        break
    xnumber = encrypt(number)
    print("Encrypted value =", xnumber)
    number = decrypt(xnumber)
    print("Decrypted value =", number)


引用:

我是编程的新手,我想知道是否有人可以帮我解决这个问题?

I'm new to programming and I was wondering if anyone can help me with this question?



所以,你没有尝试自己解决问题,毫无疑问,你只是希望我们做你的HomeWork。

HomeWork问题是你在现实生活中必须解决的问题的简化版本,目的正在学习和练习



拿一张纸和一支铅笔,手工解决问题。您手动解决问题的方法基本上就是您的算法。



我们不做您的HomeWork。

HomeWork未设置为测试你乞求别人做你的工作的技巧,它会让你思考并帮助你的老师检查你对你所学课程的理解,以及你应用它们时遇到的问题。

你的任何失败都会帮助你的老师发现你的弱点并设定补救措施。

你的任何失败都会帮助你了解什么有效,什么无效,被称为'试错'学习。

所以,试一试,重读课程并开始工作。如果您遇到特定问题,请显示您的代码并解释这个问题,我们可能会提供帮助。



作为程序员,您的工作是创建算法解决特定问题,你不能依赖别人永远为你做,所以有一段时间你必须学会​​如何。而且越快越好。

当你要求解决方案时,就像试图通过培训其他人来学习开车一样。

创建算法基本上是找到数学并做出必要的调整以适应你的实际问题。


So, you show no attempt to solve the problem yourself, you have no question, you just want us to do your HomeWork.
HomeWork problems are simplified versions of the kind of problems you will have to solve in real life, their purpose is learning and practicing.

Take a sheet of paper and a pencil, and solve the problem by hand. The way your solved the problem by hand is basically your algorithm.

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.

As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.


这篇关于如何用Python语言回答这个问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆