Computer Science 2026

HCC Website | Computer Science 2026

Assignment: Tip Calculator

Due 10/21 at 11:59

When you eat at a restaurant, you often need to calculate a tip and split the bill. Instead of doing the math in your head, write a program that does it for you!

Your program must meet the following specifications:

For example, if the user enters a $40.00 bill, 20 percent tip, and 2 people, your program might print:

Bill: $40.00
Tip (20%): $8.00
Total: $48.00
Each person pays: $24.00

Functions

A function is a reusable block of code. Use the def keyword to define a function, and use return to send a value back to the code that called it:

def add_tax(price, tax_rate):
    tax = price * tax_rate
    return price + tax

total = add_tax(10, 0.08)
print(total)  # 10.8

Example Code

Here is a starting point. Fill in the TODO comments to meet the specifications above!

def calculate_tip(bill, tip_percent):
    # TODO: calculate and return the tip amount
    pass

def calculate_total(bill, tip):
    # TODO: calculate and return the total
    pass

def split_bill(total, people):
    # TODO: calculate and return the cost per person
    pass

# Ask the user for input
bill = float( input("Enter the bill amount: $") )
tip_percent = float( input("Enter the tip percentage: ") )
people = int( input("How many people are splitting the bill? ") )

# Call your functions
# TODO

# Print the results
# TODO
Additional Challenges (not required)

When you’re happy with your tip calculator, download the .py file and submit it on Thinkwave.