如何编写将段落作为用户输入的 python 代码?


#python program of cipher text
s =input('Enter the plain Text>> ')#Tuhin T=18,u=19,....
a='abcdefghijklmnopqrstuvwxyz'
b='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
c=(int(input('Enter the code: ')))#Ex. 5
for i in range(len(s)):
j=0
k=0
if i%80==0 and i>=80:
print()
for j in range(len(a)):
if s[i]==a[j]:
if (j+c)<=25:
print(a[j+c],end="")
k=1
if (j+c)>25:
print(a[26-j-c],end="")
k=1
if s[i]==b[j]:
if (j+c)<=25:
print(b[j+c],end="")
k=1
if (j+c)>25:
print(b[26-j-c],end="")
k=1
elif j==len(a)-1 and k==0:
print(s[i],end="")

对于输入,我需要输入单行输入,但我想输入以下格式的文本:

德国出生的物理学家,以其著名的方程而闻名,该方程 被称为"世界上最著名的方程"——"E=mc2"。 阿尔伯特·爱因斯坦对牛顿力学不是很满意,因为他 认为这些理论不足以解释古典 力学和电磁场。这启发了他 发展他的奇异相对论

请记住,我主要使用Thonny和python IDE。

这个问题可以使用循环来解决,并将"返回按键"解释为""。 您可以尝试以下代码:

inp= ''
s = ''
while inp.strip('n') != 'over and out':
inp = input() #type over and out to exit loop
if inp != 'over and out':
s += inp
print(32*'--')
print(s)
#s=input('Enter the plain Text>> ')#Tuhin T=18,u=19,....
a='abcdefghijklmnopqrstuvwxyz'
b='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
c=(int(input('Enter the code: ')))#Ex. 5
for i in range(len(s)):
j=0
k=0
if i%80==0 and i>=80:
print()
for j in range(len(a)):
if s[i]==a[j]:
if (j+c)<=25:
print(a[j+c],end="")
k=1
if (j+c)>25:
print(a[26-j-c],end="")
k=1
if s[i]==b[j]:
if (j+c)<=25:
print(b[j+c],end="")
k=1
if (j+c)>25:
print(b[26-j-c],end="")
k=1
elif j==len(a)-1 and k==0:
print(s[i],end="")

复制粘贴多行文本

最新更新