The first task was to make a string of my full name, then put each name into a list using the split function, then use string indexing to isolate just the last name. Fairly straightforward, but it's a good way to make sure you have the basics down.
The next task was to fix two errors within a basic dice game. I first tried to run the game to see where the code got hung up. I then identified the problems (you can't concatenate an int to a string without first changing the type of the int, and a variable capitalization issue) and fixed them so that the code would properly run.
The final task this week was mastering loops. First, I used a while loop to append 20 integers to an empty list. When the list was complete the program printed the list. Then I chose an integer that I wanted to remove from the list and assigned it to a variable. I used the count method to check for the presence of this variable within the list in an if-else statement. The statement would print out if the integer was in the list and how many times it was there. Then I used a while that ran while the count of the chosen integer was greater than zero. For each pass through the loop it removed one instance of the chosen integer. Then the adjusted list was printed again.
Showing the results of the various basic processes covered in this lesson. |
Flowchart for the luckyList section of the code. |
No comments:
Post a Comment