Module 2's lab student outcomes were:
▪ Work with string variables in Python
▪ Use and import modules
▪ Save Python code as a script
▪ Include comments in scripts
▪ Create loops and conditional statements
▪ Iterate variables within loops to control script workflow
Our script had to successfully perform two main functions. First, we needed to create a loop that adds 20 random numbers between zero and ten to a list, which we assigned to the variable luckyList. This involved initializing an empty list, setting up a counter variable, and using a while loop to append randomly generated numbers until the list reached twenty integers. An if statement was used to check when the count reached twenty, and a break statement was included to exit the loop. Finally, we printed the list after all numbers had been added.
The next part of the assignment required us to create a loop that removes a chosen integer from the previously generated list. We assigned this integer to a variable and used an if-else statement to check if it was present in the list. If the integer was not found, we printed a message indicating this; if it was present, we used the count() method to determine how many times it appeared and printed that information. We then employed a while loop to remove the integer from the list and printed the updated list afterward.
In my initial attempt at writing this code, I completed the expected tasks. However, upon review, I realized I hadn't followed the instructions precisely and had used a different method to achieve the same goal. This was actually exciting, as I was able to rely on my intuition to complete the task, even though it wasn't the instructed method. It perfectly illustrates the principle from “The Zen of Python” that there is often “one obvious way” or a “better” way to achieve a goal. However, I'm still uncertain which of the two approaches (my initial working version versus the assignment's requested method) would truly be considered the better way in terms of general programming practices.
Below is the flow chart I created for this script. I'm anxiously looking forward to what's to come!