问题描述
我是编码的新手,我最近制作了十进制到二进制"和二进制到十进制"转换器,并且我希望raw_input的文本像打字机一样一次打出一个字母,但之后却要输入None之所以完成,是因为函数未返回任何内容.我不确定如何解决此问题,因为我希望raw_input是一个变量,并且尝试返回内容会给我带来语法错误.任何帮助表示赞赏.
I am new to coding I recently made a Decimal to Binary and Binary to Decimal Translator and I am wanting the text for the raw_input to type out one letter at a time like a typewriter, but I am getting after a None after it is done because function is not returning anything. I am not sure how to fix this because I want the raw_input to be a variable and trying to return things gives me syntax errors. Any help appreciated.
import time
import sys
def type(string):
for x in string:
sys.stdout.write(x)
sys.stdout.flush()
time.sleep(.01)
dbbd = raw_input(type('Type "db" for decimal to binary, Type "bd" for binary to decimal.'))
这是重要的部分^
有兴趣的人可以使用的完整程序: http://pastebin.com/GPw81Mi5
full program for anyone interested: http://pastebin.com/GPw81Mi5
推荐答案
raw_input
需要一个字符串作为输入
raw_input
expects a string as input
>>> help(raw_input)
您可以做的是先打印您的提示字符串,然后要求用户输入.
What you could do is the first print your prompt string and then ask for the input from the user.
import time
import sys
def typewriter(string):
for x in string:
sys.stdout.write(x)
sys.stdout.flush()
time.sleep(.01)
typewriter('Type "db" for decimal to binary, Type "bd" for binary to decimal: ')
dbbd = raw_input()
这篇关于从raw_input打印时随机无的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!