Home CPSC 110

Lab 7: The Time Library



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.



  1. Start by downloading the Pig game.
  2. Next, run it and be sure that it works as expected (without the pauses of course!)
  3. Then read through the page on the time library and see if you can find a function which will pause the program for some amount of time.
  4. If you can't find it, you can do some web research to find what you need.
  5. Import the time library into the Pig program's code with an import statement.
  6. Then, add the function to pause the program, right after the computer's roll is done.
  7. Lastly, test your program to make sure the pauses work.


Example Run

Below is an example of this program running, with the pauses in place:



When your program is finished, email the .py file to ifinlay@umw.edu.

Copyright © 2021 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.