This program has Karel move forward, dig a hole by placing a ball, crawl back through the hole, and repeat the process three times. I created separate functions like dig_hole(), crawl_hole(), run(), and spin() to keep everything organized and easier to manage. It was a little challenging because I had to think carefully about Karel’s direction after each action to make sure she didn’t get turned around the wrong way. I stayed patient, built the functions step-by-step, and fixed small mistakes along the way until it worked perfectly.
This program has Karel build two towers, each with three balls stacked vertically. I removed the turn_right and turn_around functions, so I had to manually replace them by turning left three times. I took the process step-by-step to keep it simple, and although I mostly succeeded, I made a small mistake at first by forgetting Karel needed to turn forward again at the end of building a tower. After fixing that, Karel successfully built both towers without any errors. It was a little tricky keeping track of all the turns without the shortcut functions.
This program moves Karel forward until she hits a wall, then turns left and starts placing balls while checking if the right side is blocked. If the right side is blocked, she places a ball and moves; if not, she just moves forward. It was a little hard because I had to really think about when Karel should put a ball and when she should just move without placing one. Using while loops and if statements made the logic a bit tricky, but taking it slow and testing step-by-step helped me get it working correctly.
This program controls Karel to invert the colors along her path. It checks if the current color is red, and if so, Karel paints it blue and moves forward. If the color is not red, Karel paints it red and moves forward. Once Karel reaches the end of her path, the program ensures that the last color is also inverted based on the current color. The main idea is that for each red square Karel encounters, it becomes blue, and vice versa, as she moves along. The logic is simple, but it required careful attention to both the movement and color-checking conditions to ensure Karel correctly switches colors as she travels.
This program begins by assigning values to two variables, num_apples and num_oranges, representing the number of apples and oranges, respectively. It then prints these values by converting the integers to strings using the str() function. After the initial output, the values of num_apples and num_oranges are updated—while the number of apples remains the same at 20, the number of oranges is set to 0. The program then prints the updated values of both variables. This code demonstrates basic variable assignment, string concatenation, and the ability to update and display values within a program.
For this project we did pair programming. Pair programming is when two people work on a program together. There is a Driver and a Navigator, the driver puts into the code and the navigator tell the driver what to do in the code. I was the navigator and navigated Elizabeth and Jonathan and we created a black and red piano. I call it a piano and we made it because it was something people hadn't thought of. We had lots of fun making this and were very open to ideas.
This program controls Karel to paint a checkerboard pattern. It defines two functions: checker_board_row() and move_up(). The checker_board_row() function paints alternating black and red squares along a row, moving Karel forward after each paint action. It repeats this process four times for each row, ensuring that the checkerboard pattern alternates between black and red. The move_up() function allows Karel to move up to the next row. It checks the direction Karel is facing and moves her up accordingly, adjusting her orientation after each move.The main part of the program involves a loop that calls checker_board_row() seven times to paint the checkerboard rows, with move_up() being used to move Karel to the next row after each. After completing the pattern, the program ensures Karel turns and moves to the correct final position. This program is a great example of using loops and functions to create a repetitive pattern with Karel.
For this project we had to make our own factorial code that results in non negative numbers. I made my own code including some of the studying I did on my own including terms like retun. I made the code and if, elif and else code. It acknowledged if the code is negative it will not work. I imput the numbers I wanted to use and the code produced the factorial of 5 which is 120.
Wolf Sheep Simulation
The project was to creat a hypotheses using a simulation with wolf and sheep. My hypotheses was to make the number of sheep higher than wolves but the number of grass higher than the number of sheep.
This program calculates whether a basketball player qualifies for the "All Star" status based on their points per game (ppg), rebounds per game (rpg), and assists per game (apg). The program first prompts the user to input these statistics. Each input is converted into an integer and printed. The next step is to check if the player qualifies as an All Star: a player is considered an All Star if they score at least 25 points per game, or if they score at least 10 points, 10 rebounds, and 10 assists per game. The program uses a logical condition to determine if the player meets these criteria, storing the result in the all_star variable. Finally, it prints whether the player is an All Star based on the condition. The code combines user input, condition checking, and output to evaluate and display the player's All Star status.
This program asks the user what meal they would like and responds with a suggestion based on whether they choose breakfast, lunch, or dinner. It uses an if-elif structure to check the user’s input and print the right message. It wasn’t too hard, but I had to be careful with the spelling and capitalization in both the input and the conditions to make sure everything matched correctly. Taking my time to test each option helped me catch small mistakes and get the program running smoothly.
This program generates a Punnett Square to visualize the results of a monohybrid cross. It defines several functions to display text, compute genotypes, and determine the dominant gene percentage. The function writeText() handles displaying text on the screen with customizable size, color, and alignment. The printTitle() function shows the title of the Punnett Square, which is based on the alleles of the two parent organisms. The determineGenotype() function computes the genotype of offspring by combining the alleles from each parent. The determineDominantPercentage()function checks whether the offspring has a dominant gene.The program begins by drawing the Punnett Square board and placing the alleles of the parents along the x and y axes. It then computes the genotypes for each of the four possible offspring combinations in the square. Finally, the program calculates and displays the percentage of offspring that will inherit a dominant gene. This is a useful tool for understanding Mendelian genetics and predicting the inheritance of traits.
This program simulates a coin flip using the random module. The function flip_coin() generates a random number between 0 and 1 using random.random(). If the generated number is less than 0.5, the program prints "Heads"; otherwise, it prints "Tails." The function is then called to perform a coin flip and display the result. This is a simple example of using randomness to simulate an event with two possible outcomes.
The empty list code was a deeper dive into list and removing things. We worked on the basics including if it was true or false. This was harder than the initial list work but it was still workable.
This program defines a distance function that calculates the distance between two points using the Pythagorean theorem. It takes two points as input, finds the difference in their x- and y-coordinates, and uses the math.sqrt and pow functions to compute the final distance. It was a little tricky at first to remember the right formula and how to correctly access the coordinates from the points, but breaking it down step-by-step made it easier. After a few tests, the function worked perfectly and gave the right answers.
This program creates a list of favorite movies, prints the first movie in the list, changes it to "Star Wars," and prints it again to show the update. It was pretty straightforward, but I had to be careful with indexing since lists in Python start at 0, not 1. Making sure I was changing the correct element took a little attention, but by taking it one step at a time, everything worked the way it was supposed to.
This program is an interactive "word ladder" game where the user can replace letters in a word by choosing an index and entering a new letter. It uses helper functions get_index() to safely get a valid index and get_letter() to make sure the user inputs exactly one lowercase letter. It was a bit challenging because I had to manage a lot of input checking and use loops carefully to keep the program running until the user decides to quit. Breaking the work into separate functions made it much easier to test and fix mistakes, and once I got it working, it felt really satisfying to see the word change in real time.
This program asks the user how many names they have, collects each name into a list, and then prints the first name, middle names, and last name separately. It was pretty straightforward, but I had to pay close attention to slicing the list correctly for the middle names and making sure the indexing worked even if there were only two names. Taking it step-by-step and testing with different numbers of names helped me make sure it handled all situations without errors.