...

Back to Leadership Board

Challenge #4: Landscape Design

Start Date: Novemner 3, 2023
Submit By: 8:30 am on November 10, 2023

In this project, you will learn how to use Python functions to create reusable code and for loops for repetitive actions.
We will cover the following:

  •     Python functions
  •       For loops
  •       Random function
  •       Creating a landscape design using functions, for loops, and random functions.
Watch a Video Tutorial

Video Tutorial

Challenge #4: Landscape Design

Using Python and the Turtle graphics library, create a captivating landscape design. Your task is to design a picture with at least two complex objects, not just simple shapes, and place multiple instances of these objects on the screen using for loops at random positions.

Challenge Details:
  • Watch video instructions and learn about Python functions, For loops and Random function
  • Create a new Trinket and set up the screen with a suitable background colour.
  • Functions: You must use functions to draw your landscape objects. Each object should be drawn using a separate function.
  • At Least 2 Objects: Your landscape design should include a minimum of two complex objects. These objects should be distinct and represent something more than basic shapes.
  • For Loop: Utilise a for loop to position multiple instances of these objects on the screen. The for loop should help create a sense of repetition or continuity within your landscape.
  • Random: Randomise the position or colour of your objects using random
  • Clearly Separated Horizontal Line: Your landscape design should incorporate a distinct horizontal line or element. Objects should be randomly placed correctly; for example, clouds cannot be on the ground, and cars cannot be placed in the sky.
  • Comments: Don't forget to comment your code to explain what each function and loop does.
Bonus Tip: To earn bonus points, create your own landscape with multiple elements. Avoid copying elements from the example. Be creative and design a unique landscape that stands out.
Too Hard? If this is too challenging to create your own Landscape Design, just follow the Example provided with trees and clouds, and you can still receive 3 points ->follow example here

Next
Python Functions

In Python, a function is like a pre-made set of instructions with a name. These instructions do a particular job, like multiply numbers, draw a picture, but for your computer. You can give these instructions a name, so you can use them whenever you need to do that specific job again.
Functions help make your code organized and make it easier to reuse code you've written before. So, instead of writing the same instructions over and over, you can just use the function's name. This saves time and makes your code easier to understand.

Function structure

Function with parameters

  • Function Definition (def): It starts with the def keyword, which stands for "define." This keyword tells Python that you are defining a new function.
  • Function Name: Following def, you provide a name for your function. This is the name you'll use to call the function later. Function names should follow Python's naming rules (e.g., no spaces, should start with a letter, etc.).
  • Round brakets with Parameters (if any): Inside the parentheses, you can specify parameters (inputs) that your function needs to do its job. If your function doesn't require any parameters, you still include empty parentheses.
  • Colon (:): You end the function header with a colon. The colon signifies the start of the function's code block, which is indented.
  • Indented Code Block: The code inside the function is indented. This code block contains the instructions and logic that the function performs. The level of indentation is typically four spaces or a tab.
  • Optional Return Statement: Inside the function, you can use the return statement to provide a result or output. Not all functions need to return something, but if they do, you specify what to return after the return keyword.

To call (use) a function, you use its name followed by round brakets and provide any required arguments as on example

Example:

Prev Next
Please ensure all required fields are filled in
For Loops

A for loop is like a robot that helps you do the same task over and over again without having to write the same instructions multiple times. It's handy when you have a list of things or when you want to repeat an action a certain number of times.

For Loop Syntax in Python

  • Iteration: Think of a loop as a way to repeat a set of instructions. The loop goes through each item in a list or a range of numbers, and for each item, it does something.
  • Sample with a List: Let's say you have a list of fruits like apples, bananas, and oranges. You can use a for loop to go through the list and print each fruit's name:
  • Repetition: You can also use a for loop with the range function to repeat an action a specific number of times. For example, let's say you want to print "hello" 5 times:
  • Using a For Loop with Turtle Graphics: In this example, we use a for loop to create a pattern of circles with a radius of 20. After drawing each circle, the Turtle moves forward by 20 to space them out evenly.

    Draw a square and a rectangle

Prev Next
Please ensure all required fields are filled in
Use of Random

Imagine you have a magical dice that you can roll to get a random number. The random module in Python is like that magical dice for your computer. It allows you to generate random numbers and make your programs more fun and surprising!

The random module in Python is used to generate random numbers and perform random operations. It provides various functions for working with randomness in your Python programs. Here are some common use cases of the random module:

Generating Random Integers

The random.randint(a, b) function generates a random integer between a and b (inclusive).

Example 1

Generating Random RGB Colour

Example 2

Chosing a random item from a list of values

The random.choice(list) function selects a random element from the given list or string.

Example 3

Shuffling a Sequence

The random.shuffle(list) function shuffles (randomly reorders) the elements of a list in place.

Example 4

Prev Next
Ladscape Design Example

Landscape with clouds and trees

Now it's time to draw your own Landscape Design.

Prev Next
Submit your Challenge

Submit your final project





Please select all that apply to your project:








Copy your Trinket Url

  • Click Share->Link
  • Copy the link to share your code
  • Paste link into the field

  • Do you have a question?



    Prev