Day 001 of the 100 Days of Python challenge builds a command-line tip calculator. The program collects a bill total, a tip percentage, and the number of people sharing the bill, then calculates each person’s portion.

Where Day 000 focused on collecting text and combining it into a sentence, Day 001 shifts to working with numbers — a small but important jump for beginners, since Python treats numeric input differently from plain text. This project introduces type conversion, basic math operations, and formatted currency output, all wrapped in a practical, real-world calculator you could actually use the next time you’re splitting a restaurant bill.

This guide walks through the full Day 001 source code, explains exactly how the tip calculation works, and shows how to run the project yourself.

Project Overview

The program asks for three values:

  1. The total bill
  2. The tip percentage
  3. The number of people splitting the bill

It converts the bill to a float and the other values to int values. The tip is calculated as a percentage of the subtotal, added to the bill, and divided by the number of people.

Welcome to the tip calculator!
What was the total bill?
$120
What percentage tip would you like to give? 10, 12, or 15?
15
How many people to split the bill?
4
Each person should pay: $34.50

Source Code

The Day 001 project is contained in day001/main.py in the 100daysofpython repository:

# ======================
# Project Name: Day 1 - Tip Calculator
# Section: Beginner Python Projects
# Description: Understanding data types and manipulate strings in Python to perform calculations based on user input.
# ======================

def get_number(prompt, number_type, minimum):
    """Keeps asking until the user enters a number of the given type that is >= minimum."""
    while True:
        try:
            value = number_type(input(prompt))
        except ValueError:
            print("Please enter a valid number.")
            continue
        if value < minimum:
            print(f"Please enter a number of at least {minimum}.")
            continue
        return value


def main():
    print("Welcome to the tip calculator!")

    # Get user input for bill total, tip percentage, and number of people
    sub_total = get_number("What was the total bill?\n$", float, 0)
    tip = get_number("What percentage tip would you like to give? 10, 12, or 15?\n", int, 0)
    people = get_number("How many people to split the bill?\n", int, 1)

    # Calculate the total bill including tip and how much each person should pay
    tip_amount = sub_total * (tip / 100)
    total_bill = sub_total + tip_amount
    pay_per_person = total_bill / people

    print(f"Each person should pay: ${pay_per_person:.2f}")


# Run the main function when the script is executed
if __name__ == "__main__":
    main()

How the Program Works

Collect and Validate Numeric Input

input() always returns a string, even when the user types numbers, so each answer has to be converted with float() or int(). The program does that inside a small helper function that also checks the answer:

def get_number(prompt, number_type, minimum):
    """Keeps asking until the user enters a number of the given type that is >= minimum."""
    while True:
        try:
            value = number_type(input(prompt))
        except ValueError:
            print("Please enter a valid number.")
            continue
        if value < minimum:
            print(f"Please enter a number of at least {minimum}.")
            continue
        return value
sub_total = get_number("What was the total bill?\n$", float, 0)
tip = get_number("What percentage tip would you like to give? 10, 12, or 15?\n", int, 0)
people = get_number("How many people to split the bill?\n", int, 1)

A few things are happening here:

  • The type is a parameter. number_type receives the function float or int itself, so one helper handles all three questions. sub_total uses float because a bill can include cents, while tip and people use int for a whole-number percentage and headcount.
  • Bad input is caught, not crashed on. If the user types abc, the conversion raises a ValueError; except catches it, prints a message, and continue asks again.
  • Each value has a minimum. The bill and tip can’t be negative, and people must be at least 1, which also prevents dividing by zero later.

Without this helper, float(input(...)) would crash the program on the first typo. The pattern is covered step by step in Python Basics: User Input and While Loops.

Calculate the Tip and Total

The calculation is separated into clear, readable steps:

tip_amount = sub_total * (tip / 100)
total_bill = sub_total + tip_amount
pay_per_person = total_bill / people

tip / 100 converts a whole-number percentage like 15 into a decimal like 0.15, which is then multiplied against the subtotal to find the tip amount in dollars.

Format the Output

print(f"Each person should pay: ${pay_per_person:.2f}")

The :.2f format specifier rounds a number to exactly two decimal places, which is essential for displaying currency correctly — without it, Python might print something like 34.5 or 34.499999999999996 instead of a clean 34.50.

Run the Main Function

The script wraps its work in main() and uses the main-module guard so the function runs only when the file is executed directly:

if __name__ == "__main__":
    main()

What This Project Teaches

Day 001 provides practice with:

  • Converting string input into float and int values
  • Validating input with try/except and a reusable helper function
  • Choosing the right numeric type for each piece of data
  • Performing percentage calculations
  • Formatting numbers as currency with f-strings and :.2f
  • Structuring a script with main() and the main-module guard

It also shows why choosing the right type matters: the bill requires decimal support, while a tip percentage and people count can be whole numbers.

Running the Project

git clone https://github.com/victorhugo81/100daysofpython.git
cd 100daysofpython/day001
python main.py

If you are new to Python environments, see Python Virtual Environments: Setup Guide & Best Practices.

Possible Next Steps

Once you understand the existing code, try extending it:

  • Validate that the tip entered is a reasonable percentage, instead of accepting any number
  • Round pay_per_person up to the nearest cent so the group never comes up short
  • Let the user choose a custom tip percentage instead of picking from the suggested options
  • Add a summary line showing the total bill including tip, not just each person’s share

Common Beginner Mistakes

A few pitfalls to watch for when adapting this project:

  • Forgetting to convert input at all. If you skip float() or int(), Python treats every answer as a string, and sub_total + tip_amount would raise a TypeError instead of doing math.
  • Using int() where float() is needed. If you accidentally use int() on the bill amount, any cents typed in would be silently dropped instead of rounded.
  • Skipping the :.2f format. Floating-point math can produce results like 34.499999999999996 due to how computers store decimals — formatting to two decimal places hides that imprecision for a clean, correct-looking price.

Conclusion

Day 001 of the 100 Days of Python challenge moves from text-based input to numeric calculations, showing how float() and int() convert user input into usable numbers, and how f-string formatting turns a raw calculation into clean, readable currency output.

View the Day 001 source code on GitHub, then continue through the repository’s project index as you build more Python programs, one day and one small project at a time.

Want to keep learning? These related guides pair well with this post: