More results...

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

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

Turtle Spirals

Before comleting this challenge you may want to recap on our previous two challenges:

In this challenge we are using iteration to repeat a number of instructions over and over.

Square Based Spiral #1:

Square Based Spiral #2:

Spider Web:

Your Challenge:


Tweak any of these trinkets to make your own spiral effect. Try to reproduce some of these:
spirals

Python Turtle – Iteration

Let’s Recap

In our previous challenge, we looked at using sequencing to write a program using Python Turtle to complete a drawing.

Remember when using Python Turtle, the most useful instrcutions are as follows:

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

Learning Objectives:


In this challenge we are going to use for loops to repeat a set of instructions many times. This is called iteration.

We are also going to look at nested loops. (A loop within a loop)

Challenge:


By using a loop you can repeat a set of instructions many times. This is called iteration.
Look at the following scripts: Can you create your own script using iteration?

Iteration Example 1: (Star)

Iteration Example 2: (Flower)

Iteration Example 3: (Using nested loops)

Python Turtle – Sequence

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

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

X and Y coordinates? Quadrant?


xy-coordinates
Check the above picture. Can you state three facts about X and Y coordinates and about quadrants?

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:

Python Code


Challenge #1: Sequencing


Writing a program that consists of a linear list of instructions written in a specific order is called sequencing.

Your Challenge

Use all of the instructions mentionned above to complete a drawing of your choice.
PythonTurtleChallenge

Challenge #2: Iteration


By using a loop you can repeat a set of instructions many times. This is called iteration.
Check the following challenge to create complex drawing using iteration.

Tagged with: ,

Weather Forecast Report

weather-forecastThis challenge consists of using Python to generate a random weather forecast report.

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.

What’s a list?


In Python, a list is used to save collection of values. For instance, to save a list of world cities we could declare a variable called “worldCities” and assign a list as follows:

worldCities = ["London", "Sao Paulo", "New-York", "Beijing", "Paris", "Cairo", "Dehli"]

Based on this what do you think len(worldCities) would return?
What’s about worldCities[0]?
Or worldCities[3] ?

Let’s get started!


We have started the weather forecast report for you. You will need to complete this code to provide a full weather forecast report describing:

  • What type of sky to expect: clear blue, cloudy, dark grey, etc.
  • What type of precipitations to expect: light rain, heavy snow, hail storm, fog, etc.
  • The predicted strength in mph and direction of the wind,
  • etc.

weather

Challenge #2


Create two lists of keywords, one for hot weather (e.g. hot=[“dry weather”, “hot air”, “strong sun”]) and one for cold weather (e.g. cold=[“ice on the road”,”chances of snow”, “icy wind”]).
Adapt your code to check where the temperature is high or low:

  • If your temperature is above a certain threshold add some hot weather information to your report.
  • If your temperature is below a certain threshold add some cold weather information to your report.
Tagged with:

Python Fractals

Sierpinski-triangle-ani

Fractal?


A fractal is a curve or geometrical figure, which is based on a recurring pattern that repeats itself indefinitely at progressively smaller scales. Fractals are useful in modelling some structures (such as snowflakes), and in describing partly random or chaotic phenomena such as crystal growth and galaxy formation.

Find out more about fractals: http://en.wikipedia.org/wiki/Fractal

In this challenge we will be looking at two well-known fractals both named after the Polish mathematician Wacław Sierpiński:

  • SierpiĹ„ski Triangle
  • SierpiĹ„ski Carpet

Sierpiński Triangle

The following figures show how the pattern of this fractal:
Sierpinski_triangle

Your Challenge: Sierpiński Carpet

The following figures show how the pattern of this fractal:
Sierpinski carpet
Your challenge consists of recreating this fractal by completing the following code:

unlock-access

Solution...

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

Haiku Generator in Python

haiku

Did you know?

A Haiku is a Japanese short poem consisting of three lines traditionally evoking images of the natural world. There are specific rules when writing a Haiku e.g. number of syllables in each line, however, to keep it simple we are not going to worry too much about these rules for now.

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.

Our Haiku Generator


Check the code below to generate a random Haiku:

Road Signs in HTML / CSS

road-sign-speed-limit-50In this set of challenges we are going to use CSS to recreate various road signs.

Learning Objectives

By completing these challenges you will learn more about how CSS can be used to format information on the page.
We will be looking at:

  • How to add borders, and border radius to create a rounded corner text frame.
  • How to add a shadow to the text frame.
  • How to add a gradient effect to our text frame

Challenge #1

The first challenge consists of recreating this number plate using CSS:NumberPlate

Check the following code to see how the border was created using both the border and the border-radius CSS definitions. You can also investigate how the shadow was created using the box-shadow CSS definition.

See the Pen Post-it notes by 101 Computing (@101Computing) on CodePen.

Challenge #2

For this challenge we are using exactly the same CSS definitions. By increasing the border-radius we are creating the round shape.

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

Challenge #3

Try to recreate these road signs using CSS:

road-sign-M25

road-sign-30
road-sign

roas-sign-taxi

road-sign-green

road-sign-zone-30

 

road-sign-traffic-lights

Extension Task: Using Gradients

To create the gradient we recommend using an online CSS gradient generator which will create the CSS code for you: e.g. http://www.colorzilla.com/gradient-editor/

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

Further Reading…


Should you want to learn more about CSS, the next concept that you should focus on is the different types of selectors that can be used in CSS.

Tagged with: ,
Privacy Overview

This website will store some information about your preferences on your own computer inside a tiny file called a cookie. A cookie is a small piece of data that a website asks your browser to store on your computer or mobile device. The cookie allows the website to remember your actions or preferences over time.

You can delete all cookies that are already on your computer, and you can set most browsers to prevent them from being placed. However, if you do this, you may have to manually adjust some preferences every time you visit a site, and some services and functionalities may not work.

Most browsers support cookies, but you can set your browser to decline them and can delete them whenever you like. You can find instructions here for how you can do that on various browsers.

This website uses cookies to:

  1. Identify you as a returning user and to count your visits in traffic statistics analysis
  2. Remember your custom display preferences (such as light/dark theme option)
  3. Provide other usability features, including tracking whether you have already given your consent to cookies

Enabling cookies is not strictly necessary for the website to work but it will provide you with a better browsing experience.

The cookie-related information is not used to identify you personally and is not used for any purpose other than those described here.

There may also be other types of cookies created after you have visited this website. This site uses Google Analytics, a popular web analytics service that uses cookies to help to analyse how users use the site. The information generated by the cookie about your use of this website (including your IP address) will be transmitted to and stored by Google on servers in the United States. Google will use this information for the purpose of evaluating your use of other website, compiling reports on website activity, and providing other services relating to website activity and internet usage. Google may also transfer this information to third parties where required to do so by law, or where such third parties process the information on Google’s behalf. Google undertakes not to associate your IP address with any other data held by Google.