Posts

Showing posts with the label cs50p

Featured Posts

CS50 Python , Nutrition Facts Table

Image
Nutrition Facts: Python Practice for Beginners Nutrition Facts Table for Python Practice Welcome to this comprehensive guide for Python beginners! If you are learning how to work with lists, dictionaries, and loops, this post will help you build practical skills using a real-world example: nutrition facts for fruits. Understanding how to organize and manipulate data is a key part of programming, and this exercise will give you hands-on experience. Below is a sample table of fruits and their calorie values, formatted as a Python list of dictionaries. This structure is ideal for coding exercises, projects, or even building your own nutrition calculator. You can expand this list, add new fruits, or use it as a foundation for more advanced Python tasks. Python List of Dictionaries Example: fruits = [ {'name': 'Apple', 'calories': 130}, {'name': 'Avocado', 'calories': 50}, {'name': 'Banana', 'ca...

CS50 Python | Week 6 | File I/O | Problem Set 6 | Scourgify

Image
Scourgify Pset 6 - scourgify The Challenge: The challenge involves cleaning and reformatting data from a CSV file containing student information. The data is initially structured with names and houses in a single column, separated by a comma and space, and enclosed in double quotes. The goal is to split the names into first and last names and create a new CSV file with columns for first name, last name, and house. The program, implemented in a file called scourgify.py, expects two command-line arguments: the name of an existing CSV file to read as input and the name of a new CSV file to write as output. The program uses the csv module, specifically DictReader and DictWriter, to handle the CSV operations. Additionally, the program performs error handling: If the user does not provide exactly two command-line arguments, the program exits with an error message: "Too few command-line arguments." If the specified input file cannot be read, the program exits with an error message: ...