Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

ARUN DAMODARAN
ARUN DAMODARAN
733 Points

Functions on Python

The Fizz_Buzz challenge exercise in python was re-created using functions.

There are no issues as such and I am getting the desired results but wanted to check with people in this community if the below code is the correct way to do it using functions.

Below is the code snippet for the same.

import math

def split_check(total_amt, no_of_person): if no_of_person <= 1: raise ValueError("More than one person is required to split the check") elif type(total_amt) == str: raise TypeError("Please enter an integer value") else : return math.ceil(total_amt / no_of_person)

try: total_amt = (input("What is the total amount? "))# if type(total_amt) == str:

raise TypeError("Please enter an integer value")

no_of_person = int(input("How many people? ")) amt_due = split_check(total_amt, no_of_person) except ValueError as err: print("Oh no! That's not a valid value, try again!!!") print("({})".format(err)) except TypeError as err: #print("Oh no! That's not a valid value, try again!!!") print("({})".format(err))

else : print("Each person owes ${}".format(amt_due))

1 Answer

Steven Parker
Steven Parker
231,248 Points

Please provide a link to the code page so we can see how the objective is described.

Also, when posting code to the forum, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.