社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

for循环中的Python打印格式

Mohammad Hassani • 3 年前 • 1318 次点击  
*if menuInput == '1':
     print("")
     encryptString = input("Please enter string to encrypt:")
     print("")
     offSetValue = int(input("Please enter offset value (1-94):"))
     print("")
 
     for character in encryptString:
         x = ord(character)
         y = x + offSetValue
         z = chr(y)      
         print("Encrypted string:") 
         print(z)*

我希望已加密的字符串以以下格式输出:

加密字符串:

abcde 

但它是以这种形式出现的:

Encrypted string: 
a
Encrypted string: 
b
Encrypted string: 
c
Encrypted string: 
d

我试过使用end和sep,但都没有用。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/132756
 
1318 次点击  
文章 [ 3 ]  |  最新文章 3 年前
NullUsxr
Reply   •   1 楼
NullUsxr    3 年前

通过使用fernet,它可以比移动字符串中字符的位置更安全地加密消息。

from cryptography.fernet import Fernet
if menuInput == '1':
    print()
    encryptString = input("Please enter string to encrypt:")
    print()
    key = Fernet.generate_key()
    fernet = Fernet(key)
    encryptedString = fernet.encrypt(encryptString.encode())
    print("Encrypted string:", encryptedString)
Janaka Chathuranga
Reply   •   2 楼
Janaka Chathuranga    3 年前

开始了。

if menuInput == '1':
 print("")
 encryptString = input("Please enter string to encrypt:")
 print("")
 offSetValue = int(input("Please enter offset value (1-94):"))
 print("")

 print("Encrypted string:") 
 for character in encryptString:
     x = ord(character)
     y = x + offSetValue
     z = chr(y)      
     print(z, end='')
Steve
Reply   •   3 楼
Steve    3 年前

我想这就是你想要的。

print("")
encryptString = input("Please enter string to encrypt:")
print("")
offSetValue = int(input("Please enter offset value (1-94):"))
print("")

print("Encrypted string:") 
for character in encryptString:
    x = ord(character)
    y = x + offSetValue
    z = chr(y)      
    print(z, end="")

print()

你想要 print("Encrypted string:") 在循环和使用之前 end 而不是 sep . 九月 用于分隔打印中的多个参数。 终止 是在打印内容的末尾添加的终止字符。这里我们以空字符串结束。默认的 终止 是新线人物, \n .这就是为什么你看到所有的东西都印在新的一行上。