To practice using libraries, and to experience finding what you need from a library documentation page.
In class on Wednesday we worked on writing a version of the game "Pig". You can download the code for this game here.
There is one way we can improve this program. Currently, when it's the user's turn, we do our rolls one by one, so we can see what's happening. But when it's the computer's turn, the computer just goes through all of its rolls right after the other, too fast for us to see.
We can fix this by making the computer pause for a short amount of time, like 1 second, right after the computer rolls the dice. This will slow the computer's turn down a bit so that we can follow what is happening.
In order to do this, we can use the time library. Like lots of libraries, there are lots of complex things in this library. We only need one function out. Read through the library to see if you can find which one will help us in this scenario.
Once you find the function you need, you can import the library and call it in the right place to make the program pause a little bit each time the computer rolls the die.
Below is an example of this program running, with the pauses in place:
When your program is finished, email the .py file to firstname.lastname@example.org.
Copyright © 2021 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.