Friday, June 5, 2015

Module 3 - Python Fundamentals Part II

This week we finished up our scripting basics with a lab that involved debugging a previously written code as well as adding new code ourselves.

Screenshot of code results.
The first part of the code was previously written for the lab - it is a play by play loop (of if, then, else statements) for a dice game. We were to remove the two errors in the code in order for it to run correctly. The screenshot makes it appear random, but after running the code dozens of times I can honestly say it is not. Computer gamblers beware!

After the line 'Marceline wins!' is a list of numbers - this is the result of the first block of code that I had written for the lab. This line of numbers was randomly generated from 1 to 10, but repeated up to 20 times. The code used is known as a loop, and it utilized a 'while' loop structure to obtain the results.

The last three lines of the results represent my final block of code. The first line explains that I'm removing "unlucky number 3" from the previous list of numbers. The next line shows that the number 3 had been removed, and the final line indicates that the number is no longer present. This was all accomplished using methods (such as the remove function) and conditional for statements.

It was a little tricky for me to put this all together... which is a bit disheartening since I did understand the readings. Clearly learning and doing are two very different things!

No comments:

Post a Comment