STR Coding Club logo STR Coding ClubLearn to code, together
Club Projects

Build a Python Dice Game as a Coding Club Group Project

Your club has a student who has never written a loop, another who already knows classes, and a 90 minute session to keep both of them busy.

Four students around a classroom table with two laptops showing Python code, a single white die and a paper scoresheet between them

Your club has a student who has never written a loop, another who already knows classes, and a 90 minute session to keep both of them busy. Most group projects fail that test because the easy jobs run out in 20 minutes and the hard ones need knowledge half the room does not have. A Python dice game built as a team solves this, because every piece of it can be pitched at a different level.

I have run this project with groups of four to eight learners aged 12 to 60, and it consistently finishes in two or three sessions. The game is called Pig, a classic dice game that needs only one die and a target score.

How the Python dice game works

Pig has simple rules, which is exactly why it suits a mixed group. Players take turns rolling a single six sided die. On each roll you add the number to your turn total. You may keep rolling as long as you like, but if you roll a 1, your turn total is wiped and play passes to the next person. If you choose to stop, your turn total is added to your permanent score. The first player to reach 100 wins.

That gives you random numbers, loops, conditionals, functions, input handling and a little strategy, all in a program that rarely grows past 120 lines. Beginners get something they can play within the first session, and that early win matters more than any single concept.

Splitting the work by skill level

The trick is to cut the game into modules with clear inputs and outputs, then hand them out by confidence rather than by age. Here is the split I use:

ModuleConceptsGood for
roll_die()import, random.randint, returnFirst week beginners
ask_roll_or_hold()input, while loop, string checksBeginners with a few sessions behind them
play_turn()loops, conditionals, calling functionsIntermediate learners
main game looplists, turn rotation, win checkIntermediate learners
computer playerstrategy rules, simple decision logicConfident coders
scoreboard and statsdictionaries, formatting, filesConfident coders

Agree on the function names and what each returns before anyone writes code. I put them on a whiteboard: roll_die returns an integer from 1 to 6, ask_roll_or_hold returns the string "r" or "h", and play_turn takes a player name and returns the points banked that turn. Writing this contract in plain words first is the same habit we teach in pseudocode before real code, and it stops two people building incompatible pieces.

Session plan for three meetings

Session one: a playable game

  1. Spend 15 minutes playing Pig with a real die so everyone understands the rules in their hands, not just on paper.
  2. Write the function contracts together on the board.
  3. Pairs build roll_die and ask_roll_or_hold. These take a beginner about 20 minutes with support.
  4. Stronger members write play_turn and the main loop, using stand in functions that return fixed values until the real ones arrive.
  5. In the last 15 minutes, paste everything into one file and play a two player game. It will be rough, and that is fine.

Session two: a computer opponent

This is where the confident coders earn their keep. The simplest strategy that plays well is "hold at 20": keep rolling until your turn total reaches 20, then stop. It is surprisingly strong against humans. A smarter version holds earlier when the opponent is close to 100. Meanwhile beginners can add input validation so that typing "R" or "roll" works instead of crashing.

Session three: polish and stats

Add a scoreboard, a replay option and a tally of how many times each player rolled a 1. Someone can write a simulation that plays 1,000 computer versus computer games and reports which strategy wins more often. That single task usually produces the best conversation of the whole project.

The usual advice about group roles is wrong here

Many club guides suggest giving each person a fixed role for the whole project, such as tester, designer or lead programmer. For a short project like this, I think that is a mistake.

Fixed roles lock beginners into the jobs that involve the least code. The "tester" plays the game a lot and writes very little Python. By session three they are bored and no more capable than when they started. Rotate instead. Each session, every learner should write at least one function they did not write before, even a tiny one. In my groups, the beginner who wrote roll_die in week one often writes the input validation in week two, and that progress is visible to them in a way a job title never is.

The one exception is version control. If your club uses Git, keep one confident person as the merge keeper for the whole project. Our guide to running a Git group project at your club explains why that role works better when it stays put.

Common bugs and how to coach through them

  • The turn total never resets. The variable was created outside the loop. Ask the learner to point at the line where a new turn begins.
  • random.randint(1, 6) never shows a 6. It does, they just need more rolls. Have them roll 60 times and count. This is a great small lesson about probability.
  • The game never ends. The win check compares to 100 with == instead of >=, so a jump from 96 to 102 sails past.
  • Input crashes on uppercase. Add .lower().strip() to the input before checking it.

One more appears in almost every group: the computer player rolls forever. This happens when the hold rule checks the permanent score instead of the turn total. Print both values on every roll and the mistake becomes obvious within a few turns.

Resist fixing these yourself.Ask questions until they spot it. That habit pays off long after this project.

When the game is finished, it makes a strong demo day piece, because visitors can play it in under two minutes. For more ideas that suit mixed groups, see our list of club projects that work with mixed skill levels.

Frequently asked questions

How do you make a dice game in Python?

Import the random module and use random.randint(1, 6) to simulate one roll. Wrap rolls in a while loop that asks the player whether to roll again or stop, and keep a running total. Add a second loop for turns and a check for the winning score.

Is a dice game a good first Python project?

Yes, because it uses random numbers, loops, conditionals and input in a program small enough to finish quickly. Learners see a working result in one session. It also grows naturally, so stronger learners can add an opponent or statistics without starting over.

How long does a Python dice game take a beginner group?

A playable version usually takes one 90 minute session with a group of four to eight. A computer opponent and a scoreboard add one or two more sessions. Groups with very new learners may need an extra session for input handling.

BN
Bartholomew Ng

Bartholomew taught maths for years before switching to teaching Python. He writes about the basics of the language and about teaching code without drowning learners in syntax.

More posts by Bartholomew

More in Club Projects

01doorganico 084goad 3hot8 4465456 after5internprogram ahandfulofblessings ahmadpc ahomcybersecurity allodialresources annodex antiquesandperiodcollectibles aotc asianworldkashmir beedlectrics bloggertemplatefree bluefeatheragency bodyweightsolution campaign08blog carfixadvisor catstreetcollective cbstvsports cnfanspurchasing committeeof500yearsofdignityandresistance covertopsdjs cs-kaiyuangame cuestacomunicaciontotal cxoutlet dancebetgame deskgearhub destinyvillastay detectmagazine di33 diamondsteelbuildings donmo dyanadropship emarsysfinance emimattl escapechan eskitarih evautoplay everythingweddings-orlando farmzone feedviewerapp foxstudiosscratch gamevui123 gleasongrade greetingsday hacklabasu haskell iw-kaiyun jagoanproperti jilidskripsi joltbusinessfinance juegodepokergratis juegospucca kaeru-festival latestmehndidesigns lestanzediottaviano litemagazines localcommunityhero lustrsazan mariashebets menswheels newwebstechs1 nikkit ootheday oxigenvpn plurfitness prefetial probudgetcarpetcleaning psychicmrsmartin pyaten qvantor rejoignezlogis rexzbot riselayouts ruchin rwxqsgd5 sakaltime shibiaowang shop-bot skrtips spotlesshaven tetapatrium topselller uneplanteartificielle vipertechcr webtech1223411 wo-kygaming yamaha-mekar yeknava yoybuysheets zenunwa yamaha-mekar jilidskripsi ankertoto ankertoto ankertoto