In Module 3 we were tasked with editing and completing a provided script. After reading the required texts for this module I was initially weary of the assignment. Many moons ago, programming did not come naturally to me. In various work experiences I usually edited existing code instead of creating it. So, I was happy to start the assignment by fixing/repairing some syntax issues in the provided code in Parts 1 and 2. Part 1 emphasized the fact that a module has to be imported at the beginning of the script in order to use the functions of that module in the script. Part 2 of the script was a dice game based on the length of the player's name. The two syntax error corrections pointed out that case and type are important to producing an error free script.
Part 3 of the lab required us to generate a list of 20 numbers between 0 and 10 and it told us to use the "while" loop structure. This made sense based on our reading of loop structures and the "while" loop requiring an exit condition; in our case the 20th number being generated. At first I was stuck on how to put the generated numbers in a list but the assignment hint said to create an empty list first. The Zandbergen text helped me figure out my next steps and the modules to use.
|
Flowchart for Step 3
|
Part 4 had us create a branching block and a loop structure using the list created in Part 3. Again, the clues provided in the assignment steered me in the right direction. A sketched flow chart helped me start the branching block and I also used the Zandbergen text to select the appropriate modules for both the branching and loop structures. It was awesome seeing the results print on the interactive window. I ran the script several times to make sure the correct result printed for each condition depicted in the script.
I initially thought about receiving input from the script user to assign the "unlucky" number but quickly realized this was a little more complicated because I would have to take into account that the number received could only be between 0 and 10. I would also have to create code to check for the length of the input and then truncate it to a value less than or equal to 2 in case a user typed in a value greater than 10. I may still try to figure this out.
|
Flowchart for Step 4 |
|
Python code results for dice game and list creation and removal of unlucky number |
No comments:
Post a Comment