Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why arent my functions outputting any result?

This is the problem I am working through:

The program asks the user for the number of pieces of cake and the number of party-goers, in that order. Print the number of pieces of cake each party-goer receives and the number of pieces of cake left over

My code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

pieces_cake = int(input('Number of pieces of cake:'))
party_goers = int(input('Number of party-goers: '))

def cake_per_person(pieces_cake, party_goers):
    cake_per_person = pieces_cake//party_goers
    return cake_per_person
def leftover_cake(pieces_cake, party_goers):
    leftover_cake = pieces_cake % party_goers
    return leftover_cake


print(f"Each party-goer recieves {cake_per_person} pieces of cake\n Pieces of cake that won't be distributed: {leftover_cake}")

Output:

Number of pieces of cake:12
Number of party-goers: 5
Each party-goer recieves <function cake_per_person at 0x000001947A3C51F0> pieces of cake
 Pieces of cake that won't be distributed: <function leftover_cake at 0x000001947A5B7EE0>

What am I doing wrong?

>Solution :

You are not calling the functions, just printing them.
The correct line should probably be:

print(f"Each party-goer recieves {cake_per_person(pieces_cake, party_goers)} pieces of cake\n Pieces of cake that won't be distributed: {leftover_cake(pieces_cake, party_goers)}")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading