Objectives

Students will be able to:

  • understand that a variable can be used to generate a sum which can be updated again and again

Summing

Busted!

Try to get as close to 21 as possible without going over.

 

Player 1

Cards:

Total: 0

Player 2

Cards:

Total: 0

Getting started

Open the starter code file, paste it into your IDE

Worksheet

Open the Worksheet and complete the set of tasks.

Adaptation 1

Players can enter nothing when entering their name.

Can you code the program to:

  • ask a player to enter their name
  • while the player enters "" nothing, keep asking!

Adaptation 2

In TwentyOne, card number 1 is a magic card.

If a player draws card number 1, then another card is drawn automatically before the player is asked to draw another card.

Code this adaptation.

Adaptation 3

You may have noticed that the winning logic is wrong.

For example, if player1 busts and player2 doesn't, then player2 is the winner.

If you test this scenrio, the program says Nobody won! which is not correct.

Can you fix this logic error so that the game plays as expected?

Tags

iterateauto-indent variablecompile sum machine code count-controlled loop integer pseudocodesyntax