
PYTHON PROJECTS
PYTHON PROJECTS
Coding is a form of art. A medium where you can let your creativity run free.
NUMBER GUESSING GAME (1)
REFLECTIon (2)
My next assignment in this course was a student information system made on the basis of different alternatives for arrays in Python. The first step of the process to make this project was to research different types of data sets in Python. I learned about lists, dictionaries, tuples, and sets. After, I had to decide which one was the best to use in the context of this assignment. I did some additional researching and found out that many programs like this utilize a mixture of both dictionaries and lists. This was because of the large amount of information needed to be stored for each individual. By making a list that contained dictionaries for each individual person, I was able to make the program efficient and easy to develop.
Furthermore, I learned the basics of functions in Python and how to call functions. This replaced the need for me to make complicated while loops that would be hard to edit in the future if I were to ever come back to this program. I created a main function for the menu where there are if statements to determine which feature the user wants to use. I made sure to include functions to view student info, add new students, modify details, find specific students, and even a sort function by alphabetical order. However, in the process of making the sort function, I had to watch video tutorials to find out how to even implement my idea.
In conclusion, building this system has made me learn many valuable skills including designing user-friendly interfaces, and the use cases for specific data sets in Python.
FACTORIAL RECURSION (3)
REFLECTIon (4)
Shortly after the previous factorial calculator assignment, I had to learn how to use Python’s Turtle module that allows for simple 2 dimensional visuals to be made. On top of the new lines of code I had to learn, I also had to incorporate recursion into the program. After looking at some examples online of visuals made with recursion, I decided to generate a spiral of circles that changes color with each iteration. I focused on creating a cool animation, yet not making it not too difficult for me to develop. I started off by creating a draw() function that could use recursion to continuously create the circles. In the function, I made a base case to stop the recursion when the total radius reaches 200. This is so the spirals reset every time and doesn’t go off the screen. The recursion works by repeatedly creating a circle, turning the direction, and finally recalling the function as well as adding to the radius. As mentioned before, this will continue until the radius reaches 200 where the spiral will reset to the center. In that process, I used the random module in order to create a random color for the Turtle to use.
Additionally, I learned how to utilize the Turtle environment including customizing aspects like the background color, and drawing speed to improve the visual appeal of my program. This project allowed me to understand how to use recursion for purposes outside of mathematical calculations and see how they can be translated into visual effects.
To conclude, this project helped me build my skills on recursion and my newly learned skills in visual designing in Python.
PYGAME RECURSION (5)
REFLECTIon (1)
At the start of the semester, our first assigned Python project was a number guessing game. Fortunately, I already had a general idea of how to complete this task due to my experience with Java last year when we finished the same assignment. Developing this number guessing game in Python was beneficial to my understanding of core programming concepts. I utilized concepts including: while loops, if statements, inputs, and outputs. Additionally, I experimented with modules in Python such as time to add a delay before each output, and random in order to generate random numbers for the game.
The while loops and conditional statements were essential for structuring the game so users could guess repeatedly until they found the correct answer, with options to restart or exit once the game is finished. To add a bit of uniqueness to my game, I included a portion of code dedicated to validating the user input, ensuring guesses were within the game’s range. Additionally, I made sure the program provided feedback (too high or too low) for the purpose of improving user experience. I also made sure to track the amount of turns the user required to beat the game to add a sense of accomplishment. I did this through the constant updating of a variable every re-loop.
In the future, I could plan to add more features such as increased levels to add challenge to my game. Overall, this project deepened my coding skills, and understanding of basic Python syntax.
STUDENT INFO SYSTEM (2)
REFLECTIon (3)
For my next assignment, I created a Recursion Factorial Calculator to explore the use of recursive functions in Python. The initial step was to design a function, factorial(), that would calculate the factorial of a non-negative integer provided by the user. The function uses recursion to break down the calculations into smaller steps. First I set a base case: if the input is 1, it returns 1 whereas if 0, it returns 0. Otherwise, it recursively multiplies the input by the factorial of one less than the input, creating a chain of calculations. I had to approach this assignment with an open-mind as the first time I checked out recursion during class, I had absolutely no idea of how it worked. However, I watched many tutorials online and browsed forums online in order to grasp an understanding of this concept.
To add more user-friendliness to my program, I switched the input from int (integer only) to a float input that can take decimals. This is because if you use an int(input()), when the user enters a decimal, the program throws an error message and stops functioning. However, if you use a float input, I am able to provide an if statement to check for a decimal by finding if the rounded value is equal to the input. If they are not equal, I can display an error message and continue the program without the user having the read through Python error messages. Finally, I wrapped everything except the function in a while loop to allow continuous interaction.
Ultimately, this program gave me insights on how to utilize recursion effectively and strengthened my understanding of user error handing.
TURTLE RECURSION (4)
REFLECTIon (5)
This PyGame assignment was one of the most time consuming and confusing projects I have ever done in my coding journey throughout high school. Although the recursion process was pretty similar to that of the Turtle program, there were many problems that occurred that I simply did not know how to fix. Ultimately, many issues still persist in the program currently, but at least it functions. I wanted to make this project similar to my previous project using Turtle so I made it an illusion but this time using squares instead of circles. I made a draw() function that recursively draws each square from the list of generated squares with an increasing size, so the squares appear to move toward the viewer.
The entire process can be summarized like this: the program fills the screen with black, randomly selecting a randomized color, and creates a square with an initial size of 30. This square is then added to a list that stores each square’s color and size properties, allowing the function to repeat itself and draw each square individually. Using recursion, the draw() function repeatedly calls itself to draw each square in the list, updating each square’s size for the next update. This creates almost an illusion of movement, since the squares aren’t actually moving, but rather increasing in size toward the edge of the screen.
Throughout the project, I learned more details about recursion and how to use PyGame. I worked with more advanced calculations and taught myself how to loop animations.
TERM 2
PERSONAL PROJECT
REFLECTIon
N/A