我正在编写一个小程序,当我运行它时,我得到一个无.这是一个例子:
print('Welcome to CTFTOOL')
print('Created by P.R.B.')
print('Choose your option:')
inp1 = input(print('''
1)Auto Caesar Chiper.
2)Binary-Decimal & Decimal-Binary.'''))
Run Code Online (Sandbox Code Playgroud)
在第四次打印后,我得到一个无,这与每个要求输入的打印件一起.
if inp1 == '1':
text1 = input(print('Input the text you want to decode:\n'))
autocaesarchiper(text1)
Run Code Online (Sandbox Code Playgroud)
在autocaesarchipher()函数运行之前,我得到另一个None.我一直在寻找另一个运行良好的代码,但我还没有看到问题.谢谢 :)
input() 在接受输入之前进行争论并将其打印出来.
在print()函数触发后,您看到的是无.在python中如果你的函数没有返回任何东西并且完成它默认返回None.例如:
print(print())
Run Code Online (Sandbox Code Playgroud)
输出:
#new line
None
Run Code Online (Sandbox Code Playgroud)
要修复代码,请执行以下操作:
text1 = input('Input the text you want to decode:\n')
Run Code Online (Sandbox Code Playgroud)
input将为您打印一条消息.不要将实际print功能传递给它.
inp1 = input('''
1)Auto Caesar Chiper.
2)Binary-Decimal & Decimal-Binary.''')
Run Code Online (Sandbox Code Playgroud)
该print函数的返回值是其中None的来源.