More results...

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

Random Alphabet Challenge

Welcome to the Random Alphabet Challenge! This set of three Python programming challenges is designed to test your problem-solving skills, creativity, and ability to manipulate strings and data structures.

But first let’s see if you can solve the following puzzle:

Coding Challenge #1: Find the Correctly Placed Letter.

You are given a string of 26 uppercase letters, representing a shuffled version of the English alphabet. In this shuffled string, only one letter remains in its correct position (i.e., its position in the alphabet). Your task is to write a Python script that identifies which letter is correctly placed.

Example:

  • Input: “IVKOCEPJLTAMZNSYXUWRHFBDGQ”
  • Output: “N” (because “N” is the 14th letter of the alphabet and also the 14th letter in the given string)

Python Code
Complete your code using the following online Python IDE:

Suggested Approach
Our recommended approach to solve this challenge is write a Python program to:

  • Iterate through each letter in the input string.
  • Compare the position of each letter in the string with its position in the alphabet.
  • Identify the letter where these positions match.

Testing
See if your code can find the letter in the correct position for the following shuffled alphabets:

Test # Input Values Output?
#1 SZDABJWLNRITXOUGQHEFPMVCKY
#2 OLMETJKXNGVYRZIWADSHPCQFBU
#3 XMBYCNGRQOVZPFWTJLHKEIUADS

Coding Challenge #2: Alphabet Shuffling Algorithm

In Stage 1, you wrote a Python script to identify the correctly placed letter in a shuffled alphabet string. Now, in Stage 2, we flip the script: your task is to generate a shuffled alphabet string where only one letter remains in its correct position.

You will need to write a Python program that:

  • Generates a random permutation of the 26 uppercase letters of the English alphabet.
  • Ensures that only one letter in this permutation is in its correct alphabetical position (e.g., “A” at index 0, “B” at index 1, etc.).

Coding Challenge #3: Quiz Time

This is the final stage of the Random Alphabet Challenge! In Stage 1, you identified the correctly placed letter in a shuffled alphabet. In Stage 2, you generated such a shuffled string. Now, in Stage 3, we combine both to create an interactive 10-round quiz where the player must identify the correctly placed letter in each round. Each correct answer scores one point.

Your Python script will need to:

  • Generate 10 shuffled alphabet strings (using your Stage 2 code), each with only one correctly placed letter.
  • Present each shuffled string to the user and asks them to identify the correctly placed letter.
  • Award one point for each correct answer (you may need to use your code from stage 1 for the computer to identify the correct letter and use this to check if the player’s answer is correct)
  • Display the final score at the end.
unlock-access

Solution...

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

Storage Technologies – Tic-Tac-Toe (Python Challenge)

For this challenge, we are putting a tech twist on the classic Tic-Tac-Toe game. Instead of Xs and Os, you will be working with a 3×3 grid filled with various computer storage devices. Your task is to write a Python program that not only generates this grid but also analyses it to detect if three devices of the same technology are aligned horizontally, vertically, or diagonally. Your program will give a score to the randomly generated grid where each alignment will add 10 points to the grid score.

Learning Objectives

The aim of this challenge is to work with different data structures in Python. The code provided below will use:

  • A 2D-array to store the tic-tac-toe grid (3×3 grid)
  • A list of storage devices
  • A dictionary of storage devices to store the technologies of each storage device

Your Challenge

Step 1:

Generate a 3×3 grid filled with random storage devices from the following list:

  • CD
  • DVD
  • BluRay
  • HDD
  • Floppy Disk
  • Magnetic Tape
  • USB Key
  • SD Card
  • SSD

Step 2:

Analyse the grid to check for any horizontal, vertical, or diagonal alignments of three devices from the same technology category:

  • Optical: CD, DVD, BluRay
  • Magnetic: HDD, Floppy Disk, Magnetic Tape
  • Solid State: USB Key, SD Card, SSD

Step 3:

Score points: For every alignment of three devices from the same technology, increase the score by 10.

Python Code

The code is already started for you. The code generates the random 3×3 grid of storage devices (step 1). But step 2 and 3 are incomplete. A this stage the code only checks the first row of the grid. You will need to complete this code t check all three rows as well as all thre columns and the two diagonales.

unlock-access

Solution...

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

Lesson Finder (Python Challenge)

In this project, you’ll design a Python program that stores your school timetable (e.g. 5 lessons per day, Monday to Friday) and allows you to quickly find out what lesson you have on any given day and period. Simply enter a day (e.g. Tuesday) and a lesson number (e.g. 2), and the program will instantly tell you what subject you have, who the teacher is, and where the class is held.

Example Output:

“On Tuesday, Lesson 2 you have a Maths lesson with Mr. Smith in Room 105.”

Challenge Objectives

By completing this project, you will gain experience with:

  • Data Structures: Using dictionaries and lists to store and organise your timetable.
  • Input Validation: Taking input from the user and applying validation checks on the data being entered.
  • Output Formatting: Creating a user-friendly messages for the user to provide them with the required information.

Step 1: Storing the timetable using dictionaries and lists in Python

To complete this challenge, our first step will be to store our timetable within the code of our program. We will do so by using a combination of dictionaries and lists in Python.

  • Dictionaries ({}) are used to store data as key-value pairs. For example, in the Lesson Finder, each day of the week (e.g., “Monday”) is a key, and its value is a list of lessons for that day.
  • Lists ([]) are used to store ordered collections of items. In this project, each day’s lessons are stored as a list of dictionaries, where each dictionary contains details like the subject, teacher, and room.

To store the 5-day timetable so we will use a dictionary: Each key will represent a day, and the value will be a list of lessons for that day:

timetable = {
    "Monday": [
        {"subject": "English", "teacher": "TS", "room": "201"},
        {"subject": "Maths", "teacher": "MX", "room": "105"},
        {"subject": "Biology", "teacher": "SC", "room": "302"},
        {"subject": "History", "teacher": "HT", "room": "110"},
        {"subject": "Art", "teacher": "AR", "room": "403"}
    ],
    "Tuesday": [
        {"subject": "Maths", "teacher": "MX", "room": "105"},
        {"subject": "Physics", "teacher": "PH", "room": "301"},
        {"subject": "English", "teacher": "TS", "room": "201"},
        {"subject": "PE", "teacher": "PB", "room": "Gym"},
        {"subject": "ICT", "teacher": "KN", "room": "205"}
    ],
    # Add the rest of your days here
}

JSON Syntax?

If you are familiar with JSON syntax, you may have noticed that the syntax of our timetable built using a mix of dictionaries and lists in Python mirrors the JSON syntax (JavaScript Object Notation). JSON is a lightweight data format that is easy for humans to read and write, and easy for machines to parse and generate. It’s widely used for storing and exchanging data, especially in web applications. In Python, using a combination of dictionaries and lists allows us to create a structured, nested format that is both flexible and easy to work with—just like JSON!

Step 2: Receiving and validating user inputs

Now that we have stored our timetable in our Python code, we can retrieve the two inputs from the user: The day of the Week (Monday to Friday) and the period (1 to 5) of the lesson.

For our first input, we will use a look-Up check to validate the day of the week as we will only accept the following values: Monday, Tuesday, Wednesday, Thursday, Friday.

day = input("Enter the day of the week: ").title()
while day not in ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]:
   print("Invalid input! Please try again.")
   day = input("Enter the day of the week: ").title()

For our second input, we will use a range check to make sure only a value between 1 and 5 is being entered.

lessonNumber = int(input("Enter the lesson number (1-5): "))
while lessonNumber <1 or lessonNumber >5:
   print("Invalid input! Please try again.")
   lessonNumber = int(input("Enter the lesson number (1-5): "))

Step 3: Extracting the required information from the timetable

The following code enables us to access the different values from our timetable:

lesson = timetable[day][lessonNumber - 1]
subject = lesson["subject"]
teacher = lesson["teacher"]
room = lesson["room"]

We can then output a user-friendly message to the end-user using string concatenation:

print("On " + day + ", lesson " + str(lessonNumber) + ", you have a " + subject + " lesson with " + teacher + " in room " + room + ".")

Python Code

Here is the Python code for this challenge. You can tweak this code to enter your own timetable:

Your Challenge

Can you tweak this code to start by generating a printout of the whole timetable. The output would look like this:

>>> Weekly Timetable <<<

>>> Monday
> Lesson 1: English with TS in room 201.
> Lesson 2: Maths with MX in room 105.
> Lesson 3: Biology with SC in room 302.
> Lesson 4: History with HT in room 110.
> Lesson 5: Art with AR in room 403.

>>> Tuesday
> Lesson 1: Maths with MX in room 105.
> Lesson 2: Physics with PH in room 301.
> Lesson 3: English with TS in room 201.
> Lesson 4: PE with PB in room Gym.
> Lesson 5: ICT with KN in room 205.
...
unlock-access

Solution...

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

Programming Languages Classification (Python Challenge)

Choosing the right programming language can feel overwhelming, especially for beginners. Should you learn Python, JavaScript, Swift, or something else? The answer depends on what you want to build! That’s why we are launching a fun and practical Python challenge: Build a Programming Language Recommender.

In this challenge, you’ll create a Python program that guides users to the best programming language for their project. Whether they want to build a website, a mobile app, a video game, or even create a computer program to control an embedded device, your program will ask the right questions and provide tailored recommendations.

How It Works

Your task is to write a Python program that interacts with the user through a series of questions. Based on their answers, your program will suggest one or more programming languages that fit their goals.

Your algorithm will be based on the following classification (Click on the picture to open in a new window).

The first question your program will need to ask is:

What would you like to create?

The user will have to pick an option: Website, Mobile App, Video Game, Desktop Software or Embedded System

Based on the user choice, the program will then ask follow-up questions. For instance, if the user selects “Mobile App” the program will then ask:

Is this app for an iPhone or for an Android phone?

Based on the answers provided by the end-user, the program will suggest the most relevant programming languages the end-user should consider for their project.

Decision Tree Logic

To complete this challenge you will need to use decision tree logic to implement the given classification (see picture above). To to do so you will have to use several nested IF, ELIF and ELSE statements within your code.

Here is an example of what your code may look like:

print("Welcome to the Programming Language Recommender!")
project = input("What would you like to create? (Website/Mobile App/Video Game/Desktop Software/Embedded System): ").lower()

if project == "mobile app":
   platform = input("Is this app for iPhone or an Android phone? ").lower()
   if platform == "iphone":
      print("We recommend learning Swift or Dart!")
   elif platform == "android":
      print("We recommend learning Kotlin or JavaScript, Python or Dart!")
   else:
      print("Invalid Option!")

# Add more conditions for other types of projects!

When using nested if statements within an algorithm, make sure to indent your code properly:

Python Code

Use our online Python IDE to complete this challenge:

unlock-access

Solution...

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

Uno Bank – Card Game (using Python)


Are you ready to test your luck and strategy with a Python twist on the classic Uno card game? In Uno Bank, you’ll start with $10 in your virtual bank and 10 card draws. Your goal? Maximize your bank balance by drawing cards that either add to or subtract from your total. But beware—some cards can double your money, halve it, or even change the number of draws you have left!

This challenge is perfect for Python beginners and enthusiasts who want to practice their programming skills while having fun. Let’s dive into the rules, the logic, and how you can build this game yourself.

Game Rules

Game Objective
Start with $10 and 10 draws. Draw cards to increase your bank balance. The game ends when you run out of draws, and your final balance is displayed.

Card Types and Effects

Green Cards: Increase your bank balance by the amount on the card (e.g., +3$).

Blue Cards: Decrease your bank balance by the amount on the card (e.g., -4$).

Black Cards:

  • x2: Double your current bank balance.
  • /2: Halve your current bank balance.
  • +2: Gain 2 extra draws.
  • -2: Lose 2 draws.

How to Build the Game in Python

Step 1: Set Up the Deck
Create a deck of cards with the following distribution:

    Green Cards: 4 cards (+1$, +3$, +5$, +7$)
    Blue Cards: 4 cards (-2$, -4$, -6$, -8$)
    Black Cards: 4 cards (x2, /2, +2, -2)

You can use a list to represent the deck and shuffle it at the start of the game.

Step 2: Initialise the Game

    Start with a bank balance of $10.
    Start with 10 draws.

Step 3: Game Loop

    Draw a Card: Randomly select a card from the deck.
    Apply the Effect:

      If it’s a green card, add the amount to the bank.
      If it’s a blue card, subtract the amount from the bank.
      If it’s a black card, apply the special effect (double, halve, or change the number of draws).

    Update Draws: Decrease the number of draws by 1 (unless a +2 or -2 card is drawn).
    Repeat until no draws are left.

Step 4: Display the Result
Once all draws are used, display the final bank balance.

Python Code

Complete the code for this Uno-Bank game using our online Python IDE:

Extension Task: 2-Player Mode!

Ready to take Uno Bank to the next level? In this two-player extension, you and a friend will compete to maximise your bank balances by drawing cards from a shared deck. The rules remain similar, but now, you will take turns drawing cards, and a new set of yellow cards introduces exciting (and sometimes brutal) interactions between players!

New Rules for Two-Player Mode

Objective
Both players start with $10 and 10 draws. Players take turns drawing one card at a time. The game ends when one of the players have used all their draws. The player with the highest bank balance wins!

New Cards
The game uses the same cards as before plus an extra 4 yellow cards:

  • Swap Card: Both players swap their bank balances.
  • Forward Card: Give all your money to the other player.
  • Backward Card: Take all the money from the other player.
  • Bomb Card: Your bank balance resets to $0.
unlock-access

Solution...

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

Computer Hardware Quote Generator

Have you ever wondered how computer manufacturers calculate the price of a custom PC? Or maybe you have dreamed of building your own computer but were not sure how much it would cost? In this Python challenge, you’ll step into the shoes of a computer builder! Your mission: write a program that lets users pick their ideal hardware components and generates a quote price for their custom computer.

Your Challenge

For this challenge you will create a Python program that:

  • Displays a menu of hardware options (e.g., screen size, RAM, CPU, storage).
  • Lets the user select their preferred components.
  • Calculates the total price based on their choices.
  • Outputs a detailed quote with the selected specifications and total cost.

Hardware Options

Your program should allow users to customise at least the following components:

Component Options (with Base Prices)
Screen Size 13″ (£50), 15″ (£100), 17″ (£150)
RAM 8GB (£40), 16GB (£80), 32GB (£150)
CPU Clock Speed 2.5GHz (£100), 3.2GHz (£200), 4.0GHz (£350)
Storage 256GB HDD (£30), 512GB SSD (£60), 1TB SSD (£120)
Graphics Card Integrated (£0), Dedicated (£150), High-End (£400)

Feel free to add more components or options in your code!

Sample Output

Welcome to the Custom Computer Quote Generator!

Please select your screen size:
a. 13" (£50)
b. 15" (£100)
c. 17" (£150)
> b

Please select your RAM:
a. 8GB (£40)
b. 16GB (£80)
c. 32GB (£150)
> b

Please select your CPU clock speed:
a. 2.5GHz (£100)
b. 3.2GHz (£200)
c. 4.0GHz (£350)
> c

Please select your storage:
a. 256GB HDD (£30)
b. 512GB SSD (£60)
c. 1TB SSD (£120)
> c

---
Your Custom Computer Quote:
 - Screen Size: 15" (£100)
 - RAM: 16GB (£80)
 - CPU: 4.0GHz (£350)
 - Storage: 1TB SSD (£120)
TOTAL PRICE: £650
---

Python Code

We have started the code for you but you will need to complete it to:

    Let the user pick up more hardware options
    Calculate and output the total cost of the PC
    Display a summary of the selected hardware specifications

Extension Task: Entering a Discount Code

Once the user has made their selection, they should be prompted to enter a voucher code. The system currently accepts the following three voucher codes:

  • PROMO-10 which gives a 10% discount on the total cost of the computer.
  • PROMO-20 which gives a 20% discount on the total cost of the computer.
  • PROMO-30 which gives a 30% discount on the total cost of the computer but is only applicable on computers costing £600 or more.

unlock-access

Solution...

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

Orbital Space Station – Emergency Exit Mission

Your Mission: Unlock the Emergency Exit Gate

You are aboard the Orbital Space Station K.101, orbiting the distant exoplanet K2-18b. After a catastrophic collision with space debris, the station is hurtling toward the planet’s atmosphere. You have minutes —maybe less— before the station overheats and disintegrates. Your only hope is to launch the emergency exit capsule, but the space station exit gate is sealed by 10 laser beams, each controlled by a unique logic gate circuit.

The control panel of these 10 laser beam is damaged, but the station’s technical documentation provides a truth table for each laser beam. Your task: Identify the correct logic gates circuits for each truth table to disable the lasers, one by one. Choose wisely—selecting the wrong gate will reset all 10 lasers, and time is running out!

Click on the following button to access this interactive challenge.
Orbital Space Station Emergency ExitOpen in New Window

Tagged with:

The Sieve of Eratosthenes

In this post we are going to investigate an ancient but highly effective algorithm known as the Sieve of Eratosthenes. This method, named after the Greek mathematician Eratosthenes (276 BC – 194B), is a simple and efficient way to find all prime numbers up to a specified integer. Let’s explore how it works!

What is the Sieve of Eratosthenes?

The Sieve of Eratosthenes is an algorithm that allows us to find all prime numbers up to any given limit. It does this by iteratively marking the multiples of each prime number starting from 2. The unmarked numbers that remain are prime numbers.

Step-by-Step Explanation

Let’s break down the process:

Step 1: Create a List of Numbers: Start by listing all the numbers from 2 to the desired upper limit. For example, if we want to find all prime numbers up to 100, we would list the numbers from 2 to 100. Imagine that all these numbers are in a large sieve. Progressively, the non primary numbers will be removed as they will “pass through” the sieve (see steps 2, 3 and 4)!

Step 2: Start with the First Number: The first number in the list is 2, which is a prime number. We will keep it (in our sieve) and eliminate all its multiples (i.e., 4, 6, 8, etc.) from the list because they are not prime.

Step 3: Move to the Next Unmarked Number: The next unmarked number is 3, which is also a prime number. We’ll keep it and eliminate all its multiples (i.e., 6, 9, 12, etc.) from the list.

Step 4: Repeat the Process: Continue this process with the next unmarked number, which is 5. Keep it and eliminate all its multiples. Repeat this process until you’ve gone through all the numbers in the list.

Step 5: Identify the Prime Numbers: The numbers that remain unmarked in the list are prime numbers.

Python Implementation

Here is a Python function that implements the Sieve of Eratosthenes algorithm:

Visual Representation

The following code uses Python Turtle to create a visual representation of the Sieve of Eratosthenes. The numbers in magenta are non primary numbers whereas the numbers in white are “left in the sieve” and are hence primary numbers:

Did you Know?

Eratosthenes was born in 276 BCE in Cyrene, a Greek city in modern-day Libya. He was a man of many talents and interests, which led him to study in various fields. He was a poet, an astronomer, a geographer, and a mathematician. He is especially known for his work on prime numbers (The Sieve of Eratosthenes) and for being the first person to accurately calculate the Earth’s circumference.

The Barnsley Fern Fractal

Nature has always been a source of inspiration for artists, mathematicians, and scientists alike. One of the most fascinating examples of this intersection is the Barnsley Fern, a mathematical construct that mimics the intricate patterns of a natural fern.

The Origins of the Barnsley Fern

The Barnsley Fern is named after mathematician Michael Barnsley, who introduced it in his book “Fractals Everywhere” published in 1988. Barnsley’s work on fractals and iterative function systems (IFS) revolutionised the way we understand complex natural patterns. The Barnsley Fern is a classic example of how simple mathematical rules can generate incredibly complex and beautiful structures.

The Mathematics Behind the Fern

The Barnsley Fern is created using a set of affine transformations, which include scaling, rotating, and translating points in a plane. These transformations are applied iteratively, starting from a single point. The process involves four specific transformations, each with its own probability:

  • Stem Transformation: Scales the fern vertically and places points along the stem.
  • Smaller Leaflets: Scales and rotates points to create the smaller leaflets.
  • Base Leaflets: Creates the larger leaflets at the base of the fern.

With each iteration, one of these transformations is applied based on its probability, gradually forming the shape of the fern.

Significance and Applications

The Barnsley Fern is significant in the field of fractal geometry, showing how simple mathematical rules can generate complex natural patterns. This has applications in computer graphics, where fractals are used to create realistic landscapes and vegetation. It also contributes to the study of chaos theory and dynamical systems.

Python Code

The following Python code demonstrates the iterative process. You can change within the code itself the number of dots to create different ferns.

Note that there is no Python challenge/task linked to this post. The aim of this post is just to investigate a beautiful example of the correlation between mathematics and nature. Whether you are a computer scientist, a mathematician, an artist, or simply someone who appreciates the beauty of nature, the Barnsley Fern is a fascinating subject that bridges the gap between abstract mathematics and the natural world.

Eratosthenes: The Ancient Scholar Who Measured the Earth

In the annals of scientific history, few names stand out as prominently as Eratosthenes. A polymath of the ancient world, Eratosthenes made significant contributions to various fields, including geography, mathematics, and astronomy. However, he is best known for his remarkable method to estimate the circumference of the Earth, a feat that has earned him the title of the “Father of Geography.”

Who Was Eratosthenes?

Eratosthenes was born in 276 BCE in Cyrene, a Greek city in modern-day Libya. He was a man of many talents and interests, which led him to study in various fields. He was a poet, an astronomer, a geographer, and a mathematician. His intellectual prowess caught the attention of the Ptolemaic rulers of Egypt, and he was invited to Alexandria to serve as the chief librarian of the Great Library of Alexandria, one of the most significant centres of learning in the ancient world.

Eratosthenes’ Method to Estimate the Earth’s Circumference

Eratosthenes’ most famous achievement is his calculation of the Earth’s circumference. His method was a brilliant combination of observation, geometry, and logical reasoning. Here’s a step-by-step breakdown of his approach:

Observation of the Sun’s Position: Eratosthenes noticed that on the summer solstice, the Sun was directly overhead in the city of Syene (modern-day Aswan, Egypt). This meant that the Sun’s rays were shining straight down a deep well, casting no shadow. However, at the same time in Alexandria, which is north of Syene, the Sun was not directly overhead. Instead, it cast a shadow, indicating that the Sun’s rays were coming in at an angle. (Note that the reason Eratosthenes chose Alexandria, is that he assumed Alexandria was located on the same meridian as Syene. This is a key criteria for this method to work. Though in reality this is not quite the case, which causes some slight inaccuracy in Eratosthenes estimate of the Earth circumference.)

Measurement of the Shadow’s Angle: In Alexandria, Eratosthenes measured the angle of the shadow cast by a vertical stick (a gnomon, the raised arm/stick of a sundial) at noon, on the summer solstice. He found that the angle was about 7.2 degrees, which is approximately 1/50th of a full circle (360 degrees).

Assumption of a Spherical Earth: Eratosthenes assumed that the Earth was a sphere, a concept that was widely accepted among educated Greeks at the time. He also assumed that the Sun’s rays were parallel, which is a reasonable approximation given the vast distance between the Earth and the Sun.

Calculation of the Earth’s Circumference: Using the information he had gathered, Eratosthenes reasoned that the distance between Alexandria and Syene was about 1/50th of the Earth’s circumference. He knew the distance between the two cities was approximately 5,000 stadia (a Greek unit of measurement: the exact length of a stadion is uncertain, but it is generally believed to be around 157.5 meters). So the distance between Syene and Alexandria is approximately 787.5km. By multiplying this distance by 50 to estimate the Earth’s circumference.

5,000 stadia * 50 = 250,000 stadia (or 787.5km * 50 = 39,375km)

This would make Eratosthenes’ estimate of the Earth’s circumference approximately 39,375 kilometres, which is remarkably close to the modern value of 40,075 kilometres.

Eratosthenes’ method to estimate the Earth’s circumference is a testament to the power of observation, reasoning, and mathematical prowess. His achievement is all the more remarkable considering the limited technology and resources available to him.

Python Challenge

Let’s write a small Python script to enable us to apply this method with different angle measurements made on different location on planet Earth, and let us see if we get a similar estimation of the Earth’s circumference.

Our Python program will need to:

    Take two inputs: the angle of the shadow and the distance in km from where the angle was measured and Syene’s well
    Use a mathematical formula based on Eratosthenes method:

    Output the estimated circumference of planet Earth in km, rounded to 3 decimal places
    Calculate the percentage of accuracy of this estimate, rounded to 2 decimal places, knowing that we now know that the circumference of planet Earth is 40,075km. The formula to claculate the percentage of accuracy is as follows:

    Python Code

    Type your code below:

    Testing

    To test your algorithm we have collected the approximate distances from Syene (Aswan, Egypt) of some different locations, all on the same meridian as Syene. For each location, we have recorded the angle of the shadow cast by the Sun at noon on the summer solstice (June 21st). Here is our test data:

    City Distance from Syene (km) Angle of the Shadow (degrees)
    Location 1: Alexandria, Egypt 800 7.2
    Location 2: 850 7.8
    Location 3: 2,000 18.2
    Location 4: 2,500 22.8
    Location 5: 2,800 25.6
    Location 6: 3,500 32.0
    Location 7: 4,000 36.6
    Location 8 9,000 82.2

    Can you check that your algorithm gives accurate estimate of the Earth circumference for each set of data provided in the table above.

    unlock-access

    Solution...

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