从函数返回值

时间:2014-05-06 14:22:19

标签: python function helpers

尝试创建一个确定书店折扣的程序,不确定将值从函数返回到main,但是,非常感谢帮助

def main():
print (" Please enter the amount spent on the following items:")
Books = int(input("Books: "))
Magazines= int(input("Magazines: "))
Newspapers= int(input("Newspapers: "))
print (book_disc)

def discounts(Books, Magazines, Newspapers):
       book_disc = Books - (Books *.2)
       mag_disc = Magazines - (Magazines*.1)
       news_disc =  Newspapers
return discounts
return (book_disc, mag_disc, news_disc)




main()

1 个答案:

答案 0 :(得分:0)

这是我发现的:

你有一些缩进问题

您在print (book_disc)定义之前尝试book_disc(现已删除)

return函数

需要return (book_disc, mag_disc, news_disc) discounts()发生故障return discounts

def main(): print (" Please enter the amount spent on the following items:") Books = int(input("Books: ")) Magazines= int(input("Magazines: ")) Newspapers= int(input("Newspapers: ")) def discounts(Books, Magazines, Newspapers): book_disc = Books - (Books *.2) mag_disc = Magazines - (Magazines*.1) news_disc = Newspapers return (book_disc, mag_disc, news_disc) return discounts(Books, Magazines, Newspapers) main() 需要参数

{{1}}