Python,为什么它不打印,修复方法是什么?
当我运行下面的代码时,它会打印单词“None”。它应该打印用户输入的金额。它为什么会这样做,如何修复它Python,为什么它不打印,修复方法是什么?,python,Python,当我运行下面的代码时,它会打印单词“None”。它应该打印用户输入的金额。它为什么会这样做,如何修复它 def amount(thing): amnt = int(input('How many ' + thing + ' would you like?')) bolts_amount = amount('bolts') print(bolts_amount) 您需要从函数返回一个值,否则它默认返回None def amount(thing): amnt = int(inpu
def amount(thing):
amnt = int(input('How many ' + thing + ' would you like?'))
bolts_amount = amount('bolts')
print(bolts_amount)
您需要
从函数返回一个值,否则它默认返回None
def amount(thing):
amnt = int(input('How many ' + thing + ' would you like?'))
return amnt
bolts_amount = amount('bolts')
print(bolts_amount)
在函数内部局部执行amnt=int(输入('您想要多少个'+thing+'))
不会影响函数外部的结果。您需要返回
此值,这样当您调用函数amount()
时,它将为您指定一个变量bolts\u amount