Tutorial for first year computer science students

Back to Tutorials

Dice Face - Conditional Statements

Learning Objectives

We are going to learn:

  1. How to use if and else statements.
  2. How to use the input function.

Exercises

Download the Medialib ex4 code files and 7 image files (as shown below) from the gallery and complete the program in ex4.py.

MediaLib Dice Exercise

Create a program with Medialib to draw a dice face from an inputted number:

  1. Use the input function to get the user input of an integer number (expected to be 1 to 6), after showing a prompt string like "Input an integer (1-6): ". Note: the user may input an integer out of this range. Please consider taking care of this situation in your code.
  2. Create and call a function to draw the dice face according to the inputted number (n). When n is 1, 2, ..., 6, draw dice1.png, dice2.png, ..., dice6.png using the images provided in the Medialib ex4 folder from the gallery. When n is out of the range (1-6), print a string like “Out of range!” and draw dice0.png
MediaLib Dice Exercise


Creative Commons Licence
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.