Challenges 2

Take a look at his code....


What does it do?


Look at the program and see if you were right!

Challenges

Using the skills we have looked at so far, see if you can complete the following challenges...

Whack-a-Mole

Task 1

In the example code above, the mole only appears in 1 one 3 of the holes.

Adapt the program above so that the mole will appear randomly in 1 of 5 holes.

Task 2

Adapt the program so that instead of waiting 1 second before appearing and 1 second before disappearing, it waits a random time between 0.2 seconds and 1.4 seconds.

Task 3

Adapt the program so that instead of repeating 10 times, it repeats until you have whacked 10 moles (i.e. the score is 10).

The Maths Quiz

Task 1

Create a program that:

  • Picks 2 random numbers between 1 and 100 and stores them in variables
  • Adds the 2 numbers together and stores the result in another variable.
  • Asks the player what the sum of the two numbers are and stores their answer.
  • Compares the user answer with the actual result:
    • If they match tell them they got it right
    • otherwise tell them they got it wrong and the correct answer

Task 2

Adapt the program so that it will ask them 10 different questions.

Every time they get a question right, they should get a point.

At the end of the program, give them a score out of 10.

Don’t forget to initialise the score at the beginning of the program.

Think of a Number

You are going to create a guessing game.

Maths Man should think of a random number between 1 and 100 and store it in a variable.

Maths Man will then ask you to guess what the number is.

Maths man should count each time you make a guess.

Maths Man should then tell you if your guess is too big, or too small.

If you didn’t guess correctly, Maths Man should then ask you to guess again.

If you guessed correctly, Maths Man should say well done, then tell you how many guesses it took.

Task 1

Create a program the program so it works as described above.

Task 2

Adapt the program so that is will ask you if you want to play again.

Task 3

Adapt the program so that it keeps a record of the lowest number of guesses taken to guess the number.

If the player takes less guesses than the current lowest number, then is should say well done and update the lowest score!

Files

Below are the files you will need to complete the challenges.