【问题标题】:How do I write a python code that takes paragraphs as user input?如何编写将段落作为用户输入的 python 代码?
【发布时间】:2018-09-10 17:26:35
【问题描述】:
    #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

【问题讨论】:

  • 如果问题是输入的时候不能用'enter'键换行,可以用\n字符来表示
  • 不,这不是问题,我想从 pdf 中输入复制的段落以使用密码进行编码,但我做不到!

标签: string python-3.x input encoding


【解决方案1】:

可以使用循环并将“return keypress”解释为“\n”来解决此问题。 你可以试试这个代码:

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="")

copy-paste-multiline-text

【讨论】:

    猜你喜欢
    • 2022-01-06
    • 2017-09-12
    • 2021-03-14
    • 1970-01-01
    • 2014-04-11
    • 2012-12-28
    • 1970-01-01
    • 2016-11-11
    • 1970-01-01
    相关资源
    最近更新 更多