More results...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
post
page
Python IDE Dashboard

The Gruffalo

This challenge is inspired from Julia Donaldson and Alex Sheffler’s children book: “The Gruffalo”.

In this story a little mouse describes a ferocious animal/monster called a “Gruffalo” to scare other dangerous animals (fox, snake, owl) she encounters while taking a walk in the forest.

This little mouse being very imaginative she uses plenty of frightening adjectives to describe this fictional animal.

In this challenge you are going to write a program that generates a description of a Gruffalo. Each time the program is run, a new description will be generated.

Learning Objectives:


By investigating this challenge you are going to further improve your skills at:

  • Using lists and accessing values of a list randomly,
  • Concatenating strings together to create a longer string.

Remember, in Python, a list is a collection of values. It uses [square brackets].
For instance:

colourList = ["red","blue","yellow","green","magenta"]

To access a random value from this list, you can use the random.choice method.

For instance:

colourList = ["red","blue","yellow","green","magenta"]
randomColour=random.choice(colourList)

Challenge


Complete the code below to describe your gruffalo further:

  • Has he got terrible teeth in his terrible jaws?
  • Has he got a poisonous wart at the end of his nose?
  • Has he got a black tongue and purple prickles all over his back?

Each time you run this code it will create a new description!


unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with: ,

The Twelve Days of Christmas

Christmas“The Twelve Days of Christmas” is an English Christmas carol that enumerates in the manner of a cumulative song a series of increasingly grand gifts given on each of the twelve days of Christmas.

Let’s look at how we could use Python to write the lyrics of a cumulative song.

Learning Objectives


By investigating this program you will understand more how to use lists in Python and how to use loops to iterate through all the values of a list.

Remember, in Python, a list is a collection of values. It uses [square brackets].
For instance:

giftList = ["Teddy Bear","Toy car","Electric Train"]

To find out the number of items in a list we can use the len method.

giftList = ["Teddy Bear","Toy car","Electric Train"]
numberOfGifts = len(giftList)

To iterate through all the items in a list we can use a for loop.

For instance:

giftList = ["Teddy Bear","Toy car","Electric Train"]
numberOfGifts = len(giftList)

print("My Chritmas wish list to Santa:")
for i in range(0,numberOfGifts):
  print(giftList[i])

We can then use string concatenation techniques to add punctuation:

giftList = ["Teddy Bear","Toy car","Electric Train"]
numberOfGifts = len(giftList)

letterToSanta = "Dear Santa,\n\nThis is my wish list for Christmas:\n"
for i in range(0,numberOfGifts):
  letterToSanta += "\n    " + giftList[i] + ","

letterToSanta = letterToSanta[:-1] + "." #Replace last comma with a full stop.
letterToSanta += "\n\nWishing you a Merry Christmas!"

print(letterToSanta)

btnTryCodeOnline

Python Script for The Twelve Days of Christmas:


The code below is used to write the lyrics of this Christmas carol.

Challenge:


Your challenge consists of re-using this script to adapt it to create the lyrics of another cumulative song such as:

Happy New Year!

HappyNewYear_CSS

Learning Objectives

In this challenge you will learn how to format text using CSS including how to:

  • Changing font style,
  • Changing font color,
  • Changing font weight,
  • Changing text to italic,
  • Underlining text.

We will also investigate the use of borders, border radius and background colours as well as padding and margin options.

CSS Box Model

To understand how margin, borders and padding works you need to understand the CSS Box Model. Click on this picture to find out more:CSS-Box-Model

Your Task


Complete the HTML and CSS code below to finalise customising the look & feel of this “Happy New Year!” message.

See the Pen MYevOP by 101 Computing (@101Computing) on CodePen.

Tagged with: ,

Digicode – CSS Challenge

keypadIn this challenge you are going to use CSS to create your own digicode keypad.

Learning Objectives


By completing this challenge you will familiarise yourself with CSS pseudo-classes.
A pseudo-class is used to define a special state of an element.
For example, it can be used to:

  • Style an element when a user rolls over it.
  • Style visited and unvisited hyperlinks differently.
  • Style active elements (for instance when a user clicks on an element, it becomes active).

The syntax of pseudo-classes:

selector:pseudo-class {
    property:value;
}

For instance to create a roll-over effect for hyperlinks:

A:hover {
    color:#FF0000;
}

You can also have a pseudo-class for when a link or button is active (being clicked on):

A:active {
    font-weight:bold;
}

Find out more about pseudo-classes.

Let’s see the code in practice by completing this challenge.

Your Task


Tweak the code below to create your own look & feel for your “digicode”:

See the Pen LENvrN by 101 Computing (@101Computing) on CodePen.

Scrabble Challenge

scrabbleThis challenge consists of creating a computer program that displays a random selection of 7 letters to the end-user. Each letter is given a value based on the values used in the game of Scrabble.

The user is then asked to enter a word made up using the given letters used in any order.

The program should check that the word given by the end user consists of the right letters and then calculate the score of the word based on the letter used and their values.

For instance the word “CODING” would give a score of 3 + 1 + 2 + 1 + 1 + 2 = 10

Note that for this challenge we assume that the user will give a valid English word! We will not expect the computer to check that the word actually exists in the English Language.

Learning Objectives


By completing this challenge you will discover the difference between a list and a dictionary, two data structures that can be used in Python.

You may want to read more about [lists] and about {dictionaries} first.

Complete the code


We have started the code for you. As you can see this code uses a list called randomLetters to store the value of the 7 randomly picked letters.
It also uses a dictionary called letterValues to store the value of each letter of the alphabet (Based on the game of Scrabble).

You now need to complete this code to finish the game…

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with: ,

Battleship Challenge

BattleShip_CallengeFor this challenge we are not going to recreate a full battleship game. Instead we are going to focus on randomly placing the ships on the grid using an algorithm.

The code given below uses Python Turtle to draw the full grid.
The grid is a 10 by 10 array. As Python does not support 2-dimensional arrays we created a list of lists instead.

The grid is first initialised with the value 0 in each cell of the array.
To place a ship you change the value from 0 to 1 on all the required cells.

This program uses four functions called:

  • addSubmarine to place a submarine (ship of size 1) on the grid. This function is already completed.
  • addDestroyer to place a destroyer (ship of size 2) on the grid. You need to complete this function.
  • addCruiser to place a cruiser (ship of size 3) on the grid. You need to complete this function.
  • addAircraftCarrier to place an aircraft carrier (ship of size 4) on the grid. You need to complete this function.

Note that when placing a destroyer, cruiser or aircraft carrier, you can either place it horizontally or vertically. However before placing the ship on the grid you must ensure that:

  • All the cells used to place the ship are empty (No conflict with another ship on the grid),
  • The ship will not go off the 10 by 10 grid.

The code so far…

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with: , , , ,

Roulette (Betting Game)

rouletteRules of the Game

A player starts the game with 10 chips.

For each game the player should be asked how many chips they want to bet. They should not be allowed to bet more chips than they actually own.

Then the user should be asked which number they want to bet on (between 0 and 10)

The user should be asked which colour they want to bet on:

  • Green (Number 0)
  • Red (for odd numbers)
  • Black (for even numbers)

The computer program should then “spin the wheel” by generating a random number between 0 and 10.

  • If the number generated matches the user’s number then the user should be given 10 times their initial bet.
  • If the number generated matches the user’s colour (green for 0, red for an odd number, black for an even number) then the user should be given twice their initial bet.
  • If none of the above two conditions are met, the user loses their bet.

At the end of each bet, the program should display the user’s total number of chips.

The player should be able to carry on playing for as long as they want unless they have lost all their chips. In this case the game should end.

Complete the code below to finish this game:

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

The YOLO Challenge

yoloThe YOLO challenge consists of creating an acronym generator: a program that prompts the user to enter an expression or a sentence (e.g. “You only live once!”) and in return gives the acronym matching the user input (e.g. “YOLO”)

Learning Objectives


In this challenge you will further improve your string manipulation techniques and your use of lists in Python. You will investigate how to split a string into a list and how to iterate through each item of a list.

Tips

  • First you may investigate the split() method that can be used on any string:
    myStr = "Millie,Luke,Will,Esther"
    myList = myStr.split(" ")
    #This would return a list as follows: ["Millie","Luke","Will","Esther"]
  • You may also look at the upper() and lower() method that can be used to convert a string to UPPERCASE or lowercase.
    For instance:
    myStr.upper() would convert the myStr string to uppercase.
  • To access specific characters of a string using their position you can use the following notation:myStr[0] (This would return the first character of a string called myStr).
  • Finally to iterate through all the values in a list, you may need to use a for loop:
    myList = ["Millie","Luke","Will","Esther"]
    for pupil in myList:
       print(pupil)

Your Turn


Use all of the above tips to complete the YOLO challenge:

Challenge #2


You may want to fine tune your code so that words like “the” or “a” are being ignored.

Tagged with: ,

Fizz-Buzz Game

FizzBuzzFizz buzz is a group word game for children to teach them about division. Players take turns to count incrementally, replacing any number divisible by three with the word “fizz”, and any number divisible by five with the word “buzz”.

Fizz-Buzz Challenge


For this challenge you need to write a computer program that will display all the numbers between 1 and 100.

  • For each number divisible by three the computer will display the word “fizz”,
  • For each number divisible by five the computer will display the word “buzz”,
  • For each number divisible by three and by five the computer will display the word “fizz-buzz”,

This is what the output will look like:

    1
    2
    Fizz
    4
    Buzz
    Fizz
    7

We have started the game for you… Complete this code (see below) to finish this challenge.

Tip


To find out if a number can be divided by an other number, you will need to check the remainder of the division by using the % sign in Python. For instance:

    7 % 3 = 1 because 7 is not divisible by 3.
    6 % 3 = 0 because 6 is divisible by 3.

So to check if number1 can be divided by number2, you can check if:
number1 % number2 == 0.


Challenge #2


Tweak this code to use the input command in Python. The program should ask the user to input numbers in order or type the word Fizz or Buzz when required. The program should check that the user has typed the right number or the right word and stop if not. It should then give the final score (How far the player completed the game).

Challenge #3


Improve this code further to give the players three lives. The player can make up to 3 mistakes. Each time they make a mistake they lose 10 points but carry on playing till they lose their three lives.
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with: ,

Secret Santa

Learning Objectives


This set of challenges focuses on the use of lists in Python. You will learn how to:

  • Initialise a list
  • Add and remove values to a list
  • Find out the length (number of items) of a list
  • Access specific items based on their position in the list
  • Shuffle the content of a list

Before completing this challenge you may want to read more about how Python lists work.

Challenge #1: Random Name Picker


This first challenge is done for you and gives you example of how list can be used to create a random name picker.
The challenge consists of randomly picking up 3 names from a list of pupils’ names and to make sure the same pupil cannot be picked up twice.

SecreatSanta

Challenge #2: Secret Santa


The second challenge consists of organising a Secret Santa list from a list of pupils. The program should output a list where all pupils is given the name of another pupil for who they need to get a present. For instance the output of the program may look like this:

    Laura will get a present for Tobby.
    Ryan will get a present for Laura.
    Tobby will get a present for Ryan.

With this challenge you will need to make sure that every pupil does receive a present and that a pupil does not end up having to give themselves a present.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area