Wednesday, June 6, 2018

Python Fundamentals II - Getting Acquainted with Modules and Conditionals

This week we got a bit deeper into programming with Python.  We delved deeper into using/importing modules and then were introduced to using conditional statements like if/else and while/for loops.  The particular script I worked on had three parts to it.  The first part was simply finding the errors in a section of code and fixing them.  There was two and the output you will see below shows that the errors were fixed.  This particular section of output shows 7 named players and whether their randomly assigned number based off of twice the length of their name is a winning number or not. 

The second part of the script was to create a list of 20 random numbers.  Each number had to be within 0-10.  Once the list was generated it was printed to the screen.  In the output picture below, this list will be the first one you see. 

The third part of the script was the more challenging part.  This used a combination of different conditional statements to determine if a predefined unlucky number was in the list.  If that number was not in the list, as statement was returned and the unmodified list was reprinted.  If the unlucky number was in the list, the number of times it occurred was counted, a statement was returned stating the number of times the number was in the list, actions were performed to remove the unlucky number, and then the modified list was printed to screen. 

Here is a flow chart for how my thought process worked for this last part:


And here is my output for the entirety of the script:


If you are curious as to how I achieved the outputs above, leave a comment.  I can give examples after the due date as to how I finalized my script.  Let me know if you have any questions and happy scripting to all!

No comments:

Post a Comment