More results...

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

Confetti Artwork Challenges

confetti-blueFor these challenges we will produce on screen artwork by randomly positioning confetti on different shapes of canvas. Our code will use Python Turtle to draw the canvas and the confetti.

Square Canvas


Check how the code provided below randomly positions each confetti within the boundaries of a square canvas:

Circular Canvas


Check how the code provided below randomly positions each confetti within the boundaries of a circular canvas:

Challenge #1: Ring Canvas


Adapt the code provided below to randomly position each confetti within the boundaries of a ring/doughnut shape:

Challenge #2: Diamond Canvas


Adapt the code provided below to randomly position each confetti within the boundaries of a diamond shape:

Challenge #3: Triangular Canvas


Adapt the code provided below to randomly position each confetti within the boundaries of an equilateral triangle:

unlock-access

Solution...

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

Confetti Challenge

confettiIn this Python challenge we will write a script to randomly draw confetti on a canvas while ensuring that none of the confetti overlap with each other!

Problem Decomposition


In this challenge we will need to solve the following problems:

  1. How to draw confetti on screen?
  2. How to randomly position a confetti on screen?
  3. How detect if a confetti is overlapping with another confetti?
  4. How to detect an overlap with any of the confetti already positioned on screen?
  5. How to randomise the colour of a confetti?
Problem Solution
How to draw confetti on screen? Using the Python Turtle library we can easily draw circles on the screen.
How to randomly position a confetti on screen? By generating two random numbers representing the x and y coordinates of the confetti. These coordinates will be used in Python Turtle to draw a circle on screen at the right (x,y) location.
How detect if a confetti is overlapping with another confetti? Using Pythagoras formula we can calculate the distance between two confetti.
If this distance is lower than 2*radius of a confetti, then the two confetti are overlapping.
confetti-pythagoraconfetti-overlap-detection
How to detect an overlap with any of the confetti already positioned on screen? When a confetti is placed on screen its coordinates will be appended to a list. Each time a new set of coordinates is generated we will iterate through the list of confetti one at a time (using a for loop) to check if an overlap is detected. If so, we will generate a new set of random (x,y) coordinates and repeat this process until no overlap is detected. We will then append this final set of coordinates to the list of confetti.
How to randomise the colour of a confetti? We want all confetti to have a purple shade. To do so we will randomise their colour code using the RGB codes with a random Red value (between 50 and 255), a Green value set to 0, a random Blue value (between 50 and 255).

Implementation


Check the Python code for this challenge:

Your Python Challenge


Generate confetti of random sizes (random radius between 10 and 30 pixels).
Adapt your algorithm to make sure these confetti still don’t overlap.
confetti-overlap-radius
unlock-access

Solution...

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

Binary Shift using Python

Did You Know?

Everything that is stored on a computer is stored as binary code. Binary code is made of bits (0 or 1). We often use Bytes to store data. A Byte is made of eight bits and can be used to store any whole number between 0 to 255. Check it yourself, click on the binary digits to create your own binary number:

1286432168421
11111111

128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255


Binary Left Shift


A binary left shift is used to multiply a binary number by two. It consists of shifting all the binary digits to the left by 1 digit and adding an extra digit at the end with a value of 0.
binary-left-shift

Binary Right Shift


A binary right shift is used to divide a binary number by two. It consists of shifting all the binary digits to the right by 1 digit and adding an extra digit at the beginning (to the left) with a value of 0.
binary-right-shift

Multiple-digit Left and Right Shifts


A two-digit left shift consists of two consecutive left shifts on a binary number and is the equivalent of timing this number by 22=4.

A three-digit left shift consists of three consecutive left shifts on a binary number and is the equivalent of timing this number by 23=8. (and so on…)

A two-digit right shift consists of two consecutive right shifts on a binary number and is the equivalent of dividing this number by 22=4.

A three-digit right shift consists of three consecutive right shifts on a binary number and is the equivalent of dividing this number by 23=8. (and so on…)

Python Challenge


The purpose of this challenge is to write a Python script to perform a binary shift. Our Python program will:

  • Ask the user to enter an 8-bit binary number,
  • Ask the user whether they would like to perform a left shift or a right shift,
  • Ask the user whether the number of digits they want to shift,
  • Output the resulting 8-bit binary number.

Test Plan

Test # Input Values Expected Output Actual Output
Binary Number Left/Right Shift? Number of digits
#1 00111100 Left 1 01111000
#2 00111100 Right 1 00011110
#3 00111100 Left 2 111110000
#4 00111100 Right 2 00001111
#5 00001111 Left 3 01111000
#6 00001111 Right 3 0000001

Python Code



unlock-access

Solution...

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

Code Breaker Challenges – Series 3

padlock-closed

Crack the Codes! (open full screen)


In this set of challenges, you will analyse some pseudocode to try to get the pass codes required to move on to the next levels. Levels will get more and more complex as your progress through these challenges. Will you be able to crack all the codes?

Tagged with:

Code Breaker Challenges – Series 2

padlock-closed

Crack the Codes! (open full screen)


In this set of challenges, you will analyse some pseudocode to try to get the pass codes required to move on to the next levels. Levels will get more and more complex as your progress through these challenges. Will you be able to crack all the codes?

Tagged with:

Min, Max, Mean, Median and Mod

maths-blackboardIn this Python challenge we will manipulate a list of numbers to calculate the Min, Max, Mean, Median and Mod of all these numbers.

First you may want to refresh your maths skills and check the meaning of these terms: http://www.purplemath.com/modules/meanmode.htm

Our Python code will first generate a random list of numbers.

We then added a few lines of code to calculate the min value. Your task is to complete this code to calculate the max, mean, median and mod values using a similar approach.

unlock-access

Solution...

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

Code Breaker Challenges – Series 1

padlock-closed

Crack the Codes! (open full screen)


In this set of challenges, you will analyse some pseudocode to try to get the pass codes required to move on to the next levels. Levels will get more and more complex as your progress through these challenges. Will you be able to crack all the codes?

Tagged with:

Computer Networks – Quiz!

Take the Quiz! (open full screen)


Tagged with: ,

Algorithm Terminology – Quiz!

Take the Quiz! (open full screen)


How old will you be in…

In this challenge we will write a Python program to help us find out hold we will be in the coming years! We have designed the algorithm of our program using both a Flowchart and Pseudocode.

Algorithm

FlowchartPseudocode
how-old-flowchart

year = 2017
age = INPUT("How old are you?")
FOR i FROM 1 TO 50
   year = year + 1
   age = age + 1
   OUTPUT("In " + year + ", you will be " + age + " years old.")
END FOR

Reviewing the Algorithm


Check the above pseudo-code and answer the following questions:


?
What variables are used in this code?


?
On what line is iteration used?


?
What value is used to initialise the variable year?


?
On what line is the variable age incremented?


?
On which line is string concatenation used?


?
How many lines will be displayed on screen once this program has been fully executed?


?
What would be the last line to appear on screen once this program has been fully executed?

Check the above flowchart and answer the following questions:


?
In a flowchart, what shape is used to represent a user INPUT?


?
In a flowchart, what shape is used to represent iteration?


?
In a flowchart, what shape is used to represent an OUTPUT?

Python Code


Your task is to use the algorithm provided above (either Flowchart or Pseudo-code) to code this algorithm using Python.

unlock-access

Solution...

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

Tagged with: , ,