3 回答
TA贡献1816条经验 获得超4个赞
您正在打印 的结果y_n(),请None尝试以下操作:
def name_tag():
name = input("Hello, whats your name? : ")
print(f'Hi {name}, would you like to play a game?')
y_n()
def y_n():
yes_no = input("Y/N: ")
if yes_no.lower() == 'y':
print('Cool, than lets play a game')
elif yes_no.lower() == 'n':
print('To bad!')
else:
print('Please anwser with [y] or [n]')
y_n()
如果您想使用print(y_n()),您可以更改它,以便从以下位置返回字符串y_n():
def name_tag():
name = input("Hello, whats your name? : ")
print(f'Hi {name}, would you like to play a game?')
print(y_n())
def y_n():
yes_no = input("Y/N: ")
if yes_no.lower() == 'y':
return 'Cool, than lets play a game'
elif yes_no.lower() == 'n':
return 'To bad!'
else:
print('Please anwser with [y] or [n]')
return y_n()
TA贡献1820条经验 获得超2个赞
您的代码输出None
是因为您调用print(y_n())
which 打印函数的返回值y_n()
is None
。您应该做的是不使用调用函数,print()
因为输出值已经在函数内部打印。
添加回答
举报