More results...

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

Rock-Paper-Scissors

RockScissorsPaper

Did You Know?

Rock-paper-scissors is a hand game usually played by two people, where players simultaneously form one of three shapes with an outstretched hand. The “rock” beats scissors, the “scissors” beat paper and the “paper” beats rock; if both players throw the same shape, the game is tied.

Learning Objectives

By completing this challenge you will improve your programming skills using:

  • Selection: Using if, elif and else statements.
  • Iteration: Using either a for loop or a while loop.

The Game

Check the code below, it enables a player to play against the computer:

Challenge #1

Tweak the code below to allow the players to play 5 games. Keep a score and at the end of the 5 games display the final score and display who between the player and the computer is the overall winner.

Challenge #2

Adapt your code further to play using the best-of-5 playoff: a competition between two players (user and computer) head-to-head which must win three games to win the series. Three is chosen as it would constitute a majority of games played; if one team has won three games before all five games have been played, the games that remain are omitted.

Challenge #3

Adapt your code further to play using the best-of-5 playoff (as above) but where a lead of a minimum of two clear points is required to win the game. For instance you cannot win with a score of 3-2 but you can win with a score of 4-2. (Best of 5 with a 2-clear-point lead).
unlock-access

Solution...

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

Let it snow…

Check this work from year 8 working on the snowflake challenge. Click on each snowflake to see the source code.

Snowflake_1

By Chloe

Snowflake_2

By Phil

Snowflake_3

By Poojan

Snowflake_11

By Lucy

Snowflake_4

By Ben

Snowflake_5

By Thomas

Snowflake_6

By Charlie

Snowflake_7

By Emily

Snowflake_8

By Jude

Snowflake_9

By Katie

Snowflake_10

By Harry

Snowflake_12

By Jude

Snowflake_13

By Jake

snowflake14

By Caroline

Tagged with: , ,

My Logo in Python

Using all the skills we covered in the previous few challenges, we are going to adapt a script to create our own logo using Python Turtle.

First let’s look at the following code:

Challenge


Your challenge consists of tweaking this code to create your own logo. You may want to use your initials, your full name. Alternatively you could create a logo for your form.

Choose your own colours using a colour palette.

101 Computing Logo

Snowflake Challenge

snowflake

Learning Objectives


In this challenge we will use our Python Turtle skills to draw a snowflake.

We will use iteration (For Loop) to recreate each branch of the snowflake.

Step 1: The first branch


First, let’s recap on the main Python Turtle commands:

  • myPen.color(“red”)
  • myPen.forward(100)
  • myPen.right(90)
  • myPen.left(45)
  • myPen.penup()
  • myPen.pendown()
  • myPen.goto(0,0)
  • myPen.circle(50)

snowflake_branchUsing these commands you will need to draw the following pattern:

Step 2: Using a For Loop to complete the snowflake


You are now going to use a for loop to repeat all of this code 6 times and complete your snowflake. Make sure that between each iteration you turn your turtle by 60 degrees.

Remember to use our Python Cheat Sheet to find out how the For loop works.

Video Tutorial


Challenge 2: Let it Snow


Tweak your code to create more complex snowflakes:
snowflakes
unlock-access

Solution...

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

Leap Year?

calendar

Challenge #1: Leap Year?

Write a program that lets the end-user enter a year using 4 digits (“yyyy” format).

The program should inform the user whether the year entered is a leap year or not.

Challenge #2: Valid and Invalid Dates

Write a program that lets the end-user enter a date using the “dd/mm/yyyy” format.

The program should inform the user whether the date entered is a valid date or not using the following criteria:

“mm” Month Acceptable Date Range (“dd”)
01 January 1 to 31
02 February 1 to 29 on a leap year

1 to 28 otherwise

03 March 1 to 31
04 April 1 to 30
05 May 1 to 31
06 June 1 to 30
07 July 1 to 31
08 August 1 to 31
09 September 1 to 30
10 October 1 to 31
11 November 1 to 30
12 December 1 to 31

My Name is Bond, James Bond

Challenge #1: Hello World!


Write a program that displays the message “Hello World!”

Change your program so that it asks for the end-user to type their firstname. (e.g. “John”)

The program should then display “Hello John!”

Challenge #2: My Name is Bond, James Bond!


Write a program that asks the end-user to enter their firstname and their lastame.

When the user enters their firstname (e.g.”James”) and their lastname (e.g. “Bond”) the program should then display the following output:

“Hello my name is Bond, James Bond”

What’s My Username?

Learning objectives


In this challenge we will use string manipulation techniques to manipulate text data.
In Python a String is a piece of text. It can contain letters, numbers and punctuation signs.

Hello my name is Bond, James Bond

Look at the following code which highlights some key string manipulation techniques:

Using the code above can you tell how to use Python to:

  • Prompt the user to enter their firstname?
  • Concatenate two strings together to create a longer string?
  • Retrieve the first character of a string?
  • Convert a string to uppercase?
  • Calculate the length (number of characters) of a string?
  • Convert a number into a string?

login

Challenge:


Write a program that asks the end-user to enter the following information:

  • Firstname
  • Lastname
  • Year Group

The program should then generate the end-user’s username using the following rules:

  • 2-digit year group + first letter of firstname + lastname
  • The username should be all lowercase
  • If the year group is in 1 digit only (e.g.: 7) then add a “0” in front to make it two digits e.g. “07”

Test your program with the following data:

Firstname Lastname Year Group Expected Output Actual Output
John Lennon 7 07jlennon
Paul McCartney 11 11pmccartney
George Harrison 8 08gharrison
Ringo Starr 9 09rstarr
unlock-access

Solution...

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

Car Logos using Python Turtle

Looking at the following code can you explain the purpose of each Python Turtle instructions:

  • myPen.color(“red”)
  • myPen.forward(100)
  • myPen.right(90)
  • myPen.left(45)
  • myPen.penup()
  • myPen.pendown()
  • myPen.goto(0,0)
  • myPen.circle(50)

(X,Y) Coordinates


The canvas we are drawing on (using Python Turtle) is 400 pixels wide by 400 pixels high.
Look at the canvas below to understand how (x,y) coordinates work:

Challenge #1:


Using the instructions mentioned above recreate the following car logos.
Car-Logos

The first one is done for you.

Challenge #2:


Add your own functions to recreate other car logos of your choice or create your own logo.

Gradient Generator

Learning Objectives


By completing this challenge you will gain a good understanding of how RGB colour codes and hexadecimal colour codes work and you will apply this understanding to produce a complex algorithm.

Challenge #1

Complete the code below so that it draws 6 additional squares of different colours creating a linear gradient between both the given colours.

This is what the program should display on screen:
gradient
Allow the user to change the colours and make sure your program always create the desired gradient.

Challenge #2


The second challenge is similar to challenge #1, however this time the user will enter colour codes using the hexadecimal code. e.g. #FF0000 for red.
You will need to convert these codes back into RGB code before creating your gradient.


unlock-access

Solution...

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

Volume Calculator

Learning Objectives

By completing this challenge we are going to learn how to define our own functions in Python.
We will also assign parameters to our functions.

Look at the code below used to calculate the volume of a cube. This code is based on the use of a function called getVolumeOfCube(). This function takes one parameter (width) and return the volume of the cube (in mL).

def getVolumeOfCube(width):
    volume = width * width * width
    #This calculates the volume in cubic millimeters. Divide it by 1000 to get this volume in mL
    volume=volume/1000
    return volume

#Main Program Starts Here
cubeVolume=getVolumeOfCube(50)
print("The volume of a cube with a side of 50mm is: " + str(cubeVolume) + " mL.")

Challenge #1:


Complete the following code to add 3 functions as follows:

  • getVolumeOfCylinder(radius, height)
  • getVolumeOfCuboid(width, length, height)
  • getVolumeOfCone(radius, height)

Challenge #2:


Use all of your functions to calculate the volume of each of these bottles:
BottlesABCD
unlock-access

Solution...

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