Skip to content

marceloxreis/CS50p

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🏷️ About CS50P

CS50P is an online introductory course focused exclusively on programming with Python. It teaches foundational Python concepts such as functions, variables, conditionals, and loops, alongside practical programming skills like handling exceptions, writing unit tests, using third-party libraries, regular expressions, and object-oriented programming.



💻 About the Repository

An important part of the course, it's submitting the problem sets, as well as the final project for feedback. This repository contains the solutions I've come up with for the problem sets.

Also down below are links and short descriptions for each of the projects.



📕 Academic Honesty

Keep in mind the course's academic honesty. You should try figuring out a solution yourself before looking at other implementations. Also, bear in mind that I am a beginner, I've taken the course to learn, so the solutions might not be the best implementations.



📖 Content


▶️ Notes


PNG Badge

  • Notes - contains notes I took from various sources, mostly from each week's notes section.

▶️ Week 0 - Functions, Variables


Python

  • Indoor Voice - _ Converts user input to lowercase and prints it. _

  • Playback Speed - Replaces spaces in user input with "..." and prints the modified string.

  • Making Faces - Replaces text emoticons :) with 🙂 and :( with 🙁 in user input, then prints.

  • Einstein - Calculates the energy (E) from mass (m) using Einstein's mass-energy equivalence formula (E=mcˆ2), where c is the speed of light.

  • Tip Calculator - Calculates a tip amount based on user-provided meal cost and percentage, then prints the formatted tip.


▶️ Week 1 - Conditionals


Python

  • Deep Thought - Checks if user input, after normalization, matches "42" or "fortytwo" and prints "yes" or "no".

  • Home Federal Savings Bank - Determines a monetary value ($0, $20, or $100) based on the initial characters of a normalized user-provided greeting.

  • File Extensions - Determines and prints the MIME type for a user-provided filename based on its extension, defaulting to application/octet-stream if unknown.

  • Math Interpreter - Evaluates a basic arithmetic expression (addition, subtraction, multiplication, or division) provided by the user and prints the floating-point result, handling division by zero.

  • Meal Time - dentifies and prints "breakfast time", "lunch time", or "dinner time" based on user-provided input, converting the time to a 24-hour float.


▶️ Week 2 - Loops


Python

  • Camel Case - Converts a user-provided string from camelCase to snake_case by inserting underscores before uppercase letters and converting them to lowercase.

  • Coke Machine - Simulates a vending machine transaction, prompting the user to insert specific coin denominations until a $50 amount is paid, then calculates and prints change owed.

  • Just setting up my twttr - _Removes all vowels (case-insensitive) from user input and prints the resulting string.

  • Vanity Plates - Validates if a user-provided license plate adheres to specific rules: length (2-6 characters), starting with two letters, no numbers before letters, first number not '0', and only alphanumeric characters allowed.

  • Nutrition Facts - Retrieves and prints the calorie count for a user-specified fruit by looking it up in a predefined dictionary.


▶️ Week 3 - Exceptions


Python

  • Fuel Gauge - Calculates a fuel tank's percentage full from a user-provided fraction, displaying "E" for 1% or less, "F" for 99% or more, or the percentage otherwise.

  • Felipe's Taqueria - Calculates and continuously displays the running total cost of items from a predefined menu as the user inputs them, stopping on EOF.

  • Grocery List - Reads lines of user input until EOF, then counts and prints each unique item, sorted alphabetically, along with its frequency.

  • Outdated - Parses user-provided dates in MM/DD/YYYY or Month DD, YYYY format, validates them, and prints the date in YYYY-MM-DD format.


▶️ Week 4 - Libraries


Python

  • Emojize - Replaces emoji aliases in user input with their corresponding emoji characters using the emoji library.

  • Frank, Ian and Glen's Letters - Renders user input text in ASCII art using a specified font from command-line arguments or a random font if none is specified._

  • Adieu, Adieu - Greets a list of names provided by the user, formatting the output for one, two, or multiple names with "Adieu, adieu, to...".

  • Guessing Game - Prompts the user for a positive integer level, then generates a random number within that range for the user to guess, providing "Too small!", "Too large!", or "Just right!" feedback.

  • Little Professor - Administers a 10-problem arithmetic quiz at a user-selected difficulty level, providing up to three attempts per question and displaying the correct answer after failures, then reports the final score.

  • Bitcoin Price Index - Fetches the current Bitcoin price in USD from an API, then calculates and prints the USD equivalent of a user-provided Bitcoin amount from a command-line argument.


▶️ Week 5 - Unit Tests


Python

  • Testing my twittr - Defines a function shorten that removes all vowels from a string, includes a test_shorten function to verify its behavior with various inputs, and a main function to get user input and apply the shorten function.

  • Back to the Bank - Tests the value function by asserting its output for various string inputs against expected monetary values.

  • Re-requesting a Vanity Plate - Tests the is_valid function by asserting its return value for various valid and invalid license plate strings according to predefined rules.

  • Refueling - Tests convert and gauge functions from the fuel module, verifying convert correctly processes valid fractions and raises appropriate errors for invalid inputs, and gauge accurately formats fuel levels.


▶️ Week 6 - File I/O


Python

  • Lines of Code - Takes a single command-line argument that must be a Python file, checks for its existence and .py extension, then prints the number of lines of code in that file, excluding blank lines and comments.

  • Pizza Py - Reads a specified CSV file, validates its extension and existence, then formats and prints its content as a grid-style table using the tabulate library.

  • Scourgify - Validates two command-line arguments as CSV file paths, then reads the first CSV, processes its 'name' and 'house' columns to split full names into 'first' and 'last', and writes the transformed data to the second CSV with new 'first', 'last', and 'house' headers.

  • CS50 P-Shirt - Accepts two command-line arguments (input and output image file paths), validates their extensions and existence, then overlays a "shirt.png" image onto the input image after fitting, saving the result to the output file.


▶️ Week 7 - Regular Expressions


Python

  • NUMB3RS - One Python file validates if a string is a valid IPv4 address, checking format, digit content, range (0-255), and absence of leading zeros. A separate test file thoroughly verifies this validation logic with various correct and incorrect IPv4 address formats, including edge cases and expected error handling.

  • Watch on YouTube - This Python code extracts the YouTube video ID from an HTML iframe embed code using regular expressions and constructs a YouTube URL using the extracted ID.

  • Working 9 to 5 - This set of files includes a Python script that converts time ranges from 12-hour (AM/PM) to 24-hour format, handling various input nuances and validating time components. Additionally, there is a separate test file using pytest that rigorously validates the convert function's behavior, checking for correct conversions, improper input formats, and out-of-range time values.

  • Regular, um, Expressions - This pair of Python files includes a main script that counts the occurrences of the whole word "um" (case-insensitive) in a user-provided text, and a separate test file using pytest to extensively validate the count function against various inputs, including cases where "um" appears as a whole word, part of other words, or with surrounding punctuation and spaces.

  • Response Validation - This script validates a user-provided email address, checking for a single "@" symbol and at least one dot in the domain, then prints "valid" or "invalid" based on these basic structural checks.


▶️ Week 8 - Object-Oriented Programming


Python

  • Seasons of Love - This project consists of two Python files: a main script and a test file. The main script calculates the total minutes lived since a user-provided birth date and converts this number into English words. It robustly handles date input and utilizes the inflect library for number-to-word conversion. The accompanying test file uses pytest to validate the core logic of calculating minutes lived and converting numbers to words, ensuring accuracy and proper formatting for various numerical inputs.

  • Cookie Jar - This Python code defines a Jar class that simulates a cookie jar with a fixed capacity, allowing users to deposit and withdraw cookies. It enforces constraints such as non-negative integer values for capacity, deposits, and withdrawals, and prevents exceeding capacity or withdrawing more cookies than available. A separate pytest file thoroughly tests all functionalities of the Jar class, including initialization with valid and invalid capacities, string representation, and the deposit and withdrawal methods, ensuring they handle valid operations and raise ValueError for invalid ones.

  • CS50 Shirtificate - This Python script uses the FPDF library to generate a PDF "shirtificate" document. It creates a custom PDF class that includes a header with a "CS50 SHIRTIFICATE" title and an embedded "shirtificate.png" image. The script then prompts the user for a name and generates a PDF displaying "[Name] took CS50" on the shirt, saving the output as shirtificate.pdf.


▶️ Week 9 - Et Cetera


Python



📚 Credits

First of all, a huge thank you to Prof. David J. Malan and the rest of the CS50 staff for giving us this free learning opportunity. I thoroughly recommend the CS50 course for anyone who wants to get into or improve their skills in the Computer Science field.


If you'd like to know more about CS50, I'll leave a few link down below.

About

My CS50P solutions and projects. This repository showcases my understanding of Python programming fundamentals, problem-solving, and software design. It covers topics including functions, control flow, libraries, unit testing, file I/O, and regular expressions.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages