我在每行输出中都输出"None"时遇到问题

  • 本文关键字:输出 None 遇到 问题 python
  • 更新时间 :
  • 英文 :


我正在尝试使用Playfair方法制作python密码并破译文本。但是我遇到了一个障碍,因为它似乎每行输出输出"无"。 如果有人告诉我为什么这样做,我将不胜感激。 (这是我的第一篇文章,所以请忍受我可能犯的任何错误(。 我的代码:

def cip():
key=input(print("Please Enter Keyword: "))
return key
def inp():
c = int(input(print("1.Cipher text n2.Exitnt>>")))
if c==1:
cip()
else:
exit
inp()

输出:

C:UsersXYZDesktopCodePy programs>python -u "c:UsersXYZDesktopCodePy programsPlayfair.py"
1.Cipher text
2.Exit
>>
None1
Please Enter Keyword:
NoneTron

问题是您在input()调用中使用了print()

c = int(input(print("1.Cipher text n2.De-cipher textn3.Exitnt>>")))
^^^^^

print()打印其参数,并返回None.input()使用其参数的值作为提示,因此它将打印None作为提示。

只需将提示字符串传递给input(),不要调用print()

c = int(input("1.Cipher text n2.De-cipher textn3.Exitnt>>"))

问题是当您使用带有打印的输入时。打印应在外部。

def cip():
print("Please Enter Keyword: ")
key=input()
return key
def inp():
print("1.Cipher text n2.De-cipher textn3.Exitnt>>")
c = int(input())
if c==1:
cip()
elif c==2:
decip()
else:
exit
inp()

你也可以把字符串放在input((中,像这样:

c = int(input("1.Cipher text n2.De-cipher textn3.Exitnt>>"))

最新更新