Python Fundamentals Module 02
Successful script results
The screenshot above shows the successful script results from four python scripts:
1. Printing Last Name
- My last name "Adkins" is printed as the last name from a list created using my full name.
2. Dice Game
- The results of a simulated dice game from a list of players. Each player's roll result is shown in the screenshot and the outcome (win, lose, or tie) of their roll.
3. Random Integer List
- A list of 20 randomly generated numbers from 0 to 10 was created.
4. Removing Integer from List
- An integer was chosen to be removed from the previously created random integer list.
- 9 (the chosen integer) was then removed from the list 4 times generating a new list.
Below are flowcharts for each script:
Printing Last Name
Dice Game
Random Integer List
Removing Integer from List
Here are the steps I took when creating the Removing Integer from List code:
1
I selected the number “9” as the integer to
be removed; an if else statement was used to look for the number in the list. A
statement if the number was not found in the list was also created.
2
Used the count() method to count the number
of times the number was in the list.
3
Then created a while loop to run until all
instances of the number was removed from the list.
4
Used the remove() method to remove the
number in the list.
5
The list was reprinted to show the updated
list with the number removed.
Comments
Post a Comment