Spring is a time of new beginnings and growth. With the changing of the season comes a chance for you to take your first steps toward gaining the skills to flourish in tech. But, where to begin sowing the seeds of your tech future? If you are interested in starting a tech career, training bootcamps and programming exercises are great for expanding your knowledge and skills. Not every tech role uses programming, however, many lucrative and fast-growing fields in tech do. For example, employers in data analytics and web development fields are seeking professionals with programming skills. Learning programming can be beneficial for career changers and upskillers alike.
What is Python?
Professionals in the technology industry use a variety of programming languages for creating everything from websites and mobile applications to data visualizations and more. Popular programming languages in tech include JavaScript, Python, Ruby, Go, and C. While the Institute of Electrical and Electronics Engineers Computing Society recommends JavaScript over many programming languages, Python is one of the easiest languages to learn for beginners because it has a clear, intuitive syntax that is similar to English. Each programming language has its own unique syntax, which are rules that specify how a program is written and interpreted.
Python is considered a general language that can be used to make a wide variety of programs and isn't specialized for any specific purpose. That’s also one of its biggest strengths–you can make an entire web ecosystem and never leave Python! For example, Python can be used for:
Data analysis
Building AI and machine learning algorithms
Back-end web application development
Automating tasks
Data visualization
Game development
Constructing other programming languages
Financial quantitative and qualitative analysis
Considering a career in data analytics?
Learn more about our full-time and part-time data analytics bootcamps.
To celebrate spring and new beginnings, you can try out a basic programming exercise on how to build a flower using Python. Throughout the exercise, you will learn some key Python concepts and functions. Keep in mind that Python is case-sensitive, so you’ll want to input information exactly as displayed in the steps. Your final image should look similar to this flower:
Steps to Building a Flower With Python
Before beginning this flower programming exercise, download and install Python on your computer. Python is an open-source programming language that everyone can download for free. Python can be downloaded from the official website. Be sure to select the latest Python download that matches your operating system and follow the download instructions on their website.
After you have downloaded and installed the application on your computer, you’ll open a blank Python interpreter window, also known as a “shell,” by following these steps:
Double-click the IDLE icon in your Python download folder on your computer to open the shell. In Python, the Integrated Development Environment (IDLE) is the standard development environment. Programmers who work with Python may use other development environments and code editors, but for simplicity this exercise uses IDLE.
With IDLE open, save your shell by selecting “File,” then “Save As…” from the top navigation window.
Name your Python shell file “flower” and save the file to your preferred location on your computer.
After your Python application installation and shell file setup is complete, it is time to create a virtual canvas and start building your flower.
Step 1: Import Turtle Python Library
Turtle comes pre-installed in Python and allows users to create images and shapes on a virtual canvas using a command. To access turtle in the Python library, simply type the following into the shell and press “enter” on your keyboard. Pressing “enter” will submit the characters to the machine.
import turtle |
Using “import” is a command or statement to bring a module into your Python code.
Step 2: Setup Turtle Virtual Canvas
Part 2.1: Opening the Turtle Virtual Canvas
Next, you’ll move on to opening a turtle virtual canvas. In your “shell,” type the below directly under the “import turtle” command. These lines contain variables, which give data to the computer for processing. A variable is created the moment you first assign a value to it.
t = turtle.Turtle() s = turtle.Screen() |
After the commands above are entered in the “shell,” a new window will pop up on your computer. This is your turtle virtual canvas. You’ll notice a cursor in the middle of the page. This exercise will not allow you to draw in turtle with your computer cursor or mouse. The cursor on the virtual turtle canvas is only an indicator of where the drawing will start. You’ll continue to program in the shell and your flower image will appear on the turtle virtual canvas when you complete the final steps of this exercise.
Part 2.2: Change Your Canvas Background Color
You can change the background color of your turtle virtual canvas by entering this command in the shell and typing the name of a basic color inside the quotation marks:
s.bgcolor('black') |
To have the color of your flower appear more vibrant, we recommend typing “black” into the text string. In programming, a text string, or text for short, is a cluster of characters, usually inside quotation marks. After typing in the code, press “enter” and your turtle virtual canvas background color will change to match the color you indicated inside of the command.
Part 2.3: Setting Up Your Pen
Use the code below to program the “pen" you'll be using to draft your flower. You will be setting the size of the pen, the speed at which it will draw, and the radius and color of the circle it will produce.
t.speed(0) radius = 60 t.pensize(2) color = ['red','white','red'] |
The drawing speed, size, and radius of the pen can vary, however, we recommend the programming above for a clear image. The colors of your pen can also vary. You can change the colors of the circle the pen will produce by typing out the name of the color inside of the brackets in the code string.
An unordered collection of unique items like how the colors are listed in commas and brackets in the exercise is called a “set” in programming. Be sure to use quotation marks around the color name and a comma in between each color. For this exercise, you’ll want to use three or more colors. Your colors do not have to repeat, for example, using red twice like in the view above.
Step 3: Creating Your Petals
Now that the turtle virtual canvas, pen, and circle radius and colors are set, the last few steps will be to program the circle pattern in the shell to create the petals of your flower using the text below.
This step utilizes the Python range( ) function and loops. The term “function" refers to a piece of organized, repeatable code that performs a single, specific action. Creating shapes, like a circle, is also considered a function. “Loops” like for x in range(12): are used to run a block of statements repeatedly until a given condition is satisfied for value in a sequence. In this example, once our code has run 12 times, it stops. We wouldn’t want it to keep drawing forever!
for x in range(12): t.color(color[x%3]) for i in range(8): t.circle(radius) t.right(60) radius = radius + 4 |
If you are using more than three colors, you’ll want to replace the number 3 in t.color(color[x%3]) to the number of colors you are using. This will incorporate the colors you indicated in the second step into the drawing.
For the radius = radius + 4 placement line you can either backspace or use Ctrl+[ on your keyboard to unindent your string and align it with the color string. From there, you’ll tab “enter” twice on your keyboard and your flower should appear on your virtual turtle canvas.
Your final shell should look like this:
Feel free to experiment with different colors and add your own code. That is what makes programming so fun!
If you enjoyed this exercise, and want to learn the coding or programming skills needed to launch a tech career, Fullstack Academy offers beginner data analytics bootcamps that teach Python for data visualization and JavaScript-based coding bootcamps for web development. For a free introduction to HTML, CSS, and JavaScript fundamentals, you can also take our free self-paced coding course online.
Considering a career in data analytics?
Learn more about our full-time and part-time data analytics bootcamps.