Python Fundamentals - Module 2

 This second module of the Python programming course is an introduction to the main operations of a python scripts. Our cohort was required to learn how to manipulate lists, fix errors within provided code, populating random integers into lists, using 'while' and 'if' statements, using functions and methods, and running an entire script. 

 The lab first required us to to separate and print our last name from a list containing our full name. This was accomplished creating a new variable and using a simple spit function. 

Next, we were provided a script for a dice game (containing random integers, a theme for this module) and were tasked with correcting the code. If the script is run, python will automatically prompt an error code. By deducing ones way through each of these codes, eventually all of the errors will be isolated and rectified. Some were as simple as having the letter x in two different cases. 

After completing this section, we were tasked with creating a list of 20 random numbers ranging between 0 and 10. Being able to arrange our code in the appropriate logical sequence was a rather tricky practice. The interesting thing in coding is that it appears to shape one's thought process. All expressions must be sequential, so a deep analysis of most of our rote thought processes was a must. 

To accomplish this, we were tasked with using 'if' and 'while' loops to repeat the counter with the newly ascribed value. We achieved these values through the use of methods and functions. Methods such as 'count,' 'remove,' and 'randint' allowed us to scour various objects with different arguments. 

Once our list was generated, we were deemed to chose and unlucky number, which I ascribed as 4, and had to have the code tell us, via printing a string, whether that number appears in the random number list. If it did not, we then had to create a string saying that it did not. If it did, we had to write a string saying how the unlucky number would be removed from the list the amount of times it appears. 

A while loop was then used to remove this unlucky integer from the printed list. We did this through the use of the remove method. 

We then printed our code. The image of the results appears at the bottom. 

Once of thing I learned through discussions with my professor was how to simplify our expressions to still achieve the desired result. In my original code, when trying to create the code for how many times my unlucky number appeared in my random integer list. I would ask to see if the amount of my lucky number was over 0, that then directed to the string describing that it either wasn't or was. 

The simpler way to do this is just use the language 'not in' instead of asking if the amount of our lucky number is equal to 0. We could ask if our lucky number is 'not in' our number list and if it is or isn't, we could direct from there. We used the same layout with a while statement when telling the program to remove this number. We were simply able to say while our unlucky number is 'in' our list, remove it (using a method).

Comments