As part of Net Ninja’s Python Masterclass, we worked on a project to apply foundational Python concepts by building a bar tab generator. This command-line tool prompts users to input details like table number, drink orders, and the price of each drink. Once all the information is entered, the tool generates a CSV file containing the complete order, the subtotal, a 20% tip, and the total.

I’m proud of this one! Here’s the GitHub link.

What I Learned

Working with Python has been a lot of fun, allowing me to test and apply my prior programming knowledge. I have experience working with JavaScript on personal projects and have completed several college programming courses focused on Java. While no programming language is perfect, I’m excited to dive deeper into Python. Lately, I’ve gained a clearer sense of direction for my career, and I know this will be an essential skill to get me where I want to go.

Error Handling with try-except

Error handling is crucial for creating robust applications and try-except blocks are an effective way to manage exceptions or errors that may come up during execution. It’s good practice to anticipate potential errors, like invalid user input for file access issues; the try block ensures that the program continues to run smoothly, while the except block handles specific exceptions without breaking the program.

# get the table number from user
while True:
	try:
		table_num = int(input("Table number: "))
		print(f"Starting a tab for Table {table_num}...")
		break
	except ValueError:
		print("Not a valid number")
		continue

In the main function, the user is prompted to enter a table number and ensure it’s a valid integer. It repeatedly asks for input in a while True loop and uses a try-except block to catch any ValueError exceptions (if the user enters something other than a number). If the input is valid, it stores the table number, prints a message to confirm the tab has started, and breaks the loop. If the input is invalid, it prints an error message and prompts the user until a valid number is entered.

Working with Modules

Writing Modular Code

🚧 Work in progress…