This week, our assignment focused on Python basics, including working with strings, fixing errors in loops, building and modifying lists, and learning how to use both for and why loops to control code behavior. The screenshot below shows the successful results from all four parts of the lab assignment (Figure 1).
The screenshot displays the output of my full script. It starts with my last name printed from a list, followed by the dice game output where each player’s roll and result is shown. Next is the randomly generated list of 20 numbers between 0 and 10. Finally, the results show how many times the number 7 appeared in the list, confirmation that it was removed, and the final cleaned-up list.
I worked through each task step using the provided template and building out the code in ArcGIS Notebook. Some things went smoothly, such as printing my last name using indexing from a list, while others took some trial and error, especially working with while loops and understanding how to cleanly remove elements from a list.
In the dice game, the tricky part was catching a type mismatch between a string and an integer. I was initially confused by the error, but realized the problem was that I was trying to add an integer (the result of a dice roll) to a string without converting it first. A quick fix using str() cleared it up.
Creating the list of 20 random integers using a while loop helped reinforce how loop conditions work. I used a counter variable to track how many numbers had been added, and used an if statement with a break to stop the loop once I reached 20.
The final step, removing a selected number from the list, was a solid test of logic. I used an if statement to check if the number was in the list, and then a while loop to remove every instance of it using remove(). I also used count() beforehand to see how many times it appeared, which helped me double-check the results. Seeing the list before and after was a simple but helpful visual to confirm everything worked.
Overall, this assignment was a good balance of basic review and new concepts. Each step built on the last, and having to troubleshoot small errors along the way helped reinforce what I was learning.


