我一直从我的python程序返回None

时间:2017-11-28 11:09:53

标签: python

代码如下

# Cristmas Quiz
import time
from time import *

score = 1
quiz_q = [ 
        'how many turtle doves', 
        'how many French Hens',
        'how many gold rings', 
        'how many Lords a leaping?'
        ]

quiz_a = [2,3,5,10]

for n in range(4):
    question = input(print(quiz_q[n]))
    if quiz_a[n] == question:
        score += 1
    else:
        print("your score was ",score-1)
        time.sleep(5)
        quit()

返回:

how many turtle doves
None 

我环顾四周,但所有其他的qustion似乎都在引用函数和return vs print()的使用

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:3)

正如评论中所建议的那样,我正在重新格式化我的评论作为答案。我将尝试详细说明我的解释。

您正在调用print函数,该函数输出文本,然后返回None。这可能不直观,但从任何不返回任何其他内容的函数返回None

然后None作为参数传递给input函数,将其转换为文本,输出然后等待输入。