输出中没有

时间:2013-10-23 08:54:32

标签: python-3.x

抱歉,我希望用户输入一封信,但我不明白为什么显示屏会显示无。

import random
hangmanList = {"fruit":["apple","banana","orange"]}
topicList = ["fruit"]
randomTopic = random.choice(topicList)
wordList = hangmanList[randomTopic]
questionList = random.choice(wordList)

def main():
    print("Welcome to the Hangman Game")
    print("---------------------------")
    print("Please choose 1 letter at a time")
    print("Topic is: ",randomTopic)
    guesses = input(print("Guesses: "))

main()

输出显示:

欢迎来到Hangman游戏


请一次选择1个字母

主题是:水果

猜测: 无

2 个答案:

答案 0 :(得分:1)

只需使用:

guesses = input("Guesses: ")

print返回Noneinput将其参数打印为提示符。

答案 1 :(得分:1)

应该是

guesses = input('Guesses: ')

目前它是None,因为print()函数没有返回值,因此它的结果是None。所以

guesses = input(print('Guesses: ')) 
# is
guesses = input(None)