Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3:将多行打印到一行_Python_Python 3.x - Fatal编程技术网

Python 3:将多行打印到一行

Python 3:将多行打印到一行,python,python-3.x,Python,Python 3.x,我用谷歌机器搜索过Stackoverflow和其他网站上的线程,但没有任何东西能告诉我我在寻找什么 我是使用Python3编程的新手,所以我的大部分内容都非常基础 我正在编写一个程序,允许我使用Caeser密码对文本文件进行加密和解密。从用户处获取短语并应用用户给定的移位 这就是我现在正在处理的问题: 一些代码只是作为占位符存在其中,直到我进一步深入到我的程序中 import string print ("1) Encrypt") print ("2) Decrypt") print ("3)

我用谷歌机器搜索过Stackoverflow和其他网站上的线程,但没有任何东西能告诉我我在寻找什么

我是使用Python3编程的新手,所以我的大部分内容都非常基础

我正在编写一个程序,允许我使用Caeser密码对文本文件进行加密和解密。从用户处获取短语并应用用户给定的移位

这就是我现在正在处理的问题:

一些代码只是作为占位符存在其中,直到我进一步深入到我的程序中

import string
print ("1) Encrypt")
print ("2) Decrypt")
print ("3) Decrypt w/o Shift")

Choice = input("Choice: ")

if Choice == '1':
    message = input("Message: ")
    shift = int(input("Shift: "))
    newmsg = ''
    for char in message:
        if char.isupper():
            new = (ord(char)-ord('A')) + shift
            newmsg = chr(new+ord('A'))
            print (newmsg, end="")
        else:
            print(" ")


elif Choice == '2':
    print ("2")

elif Choice == '3':
    print ("3")
当我输入一个测试短语时,例如“这是一个测试”,它会给我正确加密的输出,但它显示如下:

V
J
K
U

K
U

C

V
G
U
B
这是一个2的“移位”

如果我在print语句中添加
end='
,它将输出为:

V J K U
K U
C
V G U V
VJKU
KU
C
VGUV
如果我在print语句中添加
end='
,它将输出为:

V J K U
K U
C
V G U V
VJKU
KU
C
VGUV
我正在寻找以下输出:

VJKU KU C VGUV
我知道这是我忽略的愚蠢的事情。任何帮助都将不胜感激。非常感谢。

使用
end=”“
,但也要将此参数添加到行中

print(" ")
否则,此行将添加新行

也就是说,您最好先收集列表中的字符,然后只调用一次
print()

print("".join(list_of_characters))
另一种方法是使用
str.maketrans()
创建字符转换表,并使用
str.translate()
使用
end=“”
,同时将此参数添加到行中

print(" ")
否则,此行将添加新行

也就是说,您最好先收集列表中的字符,然后只调用一次
print()

print("".join(list_of_characters))

另一种方法是使用
str.maketrans()
创建字符转换表,并将其应用于
str.translate()

啊,我忘记了第二个print语句。那是票。非常感谢你。愚蠢的错误>>啊,我忘了第二份打印声明。那是票。非常感谢你。愚蠢的错误>_