In this video, we write our first web request.
In this video, we use standard input and output in Python to process data piped to us from other applications.
Some of us grew up clicking around in MS Paint on Windows. Others may enjoyed the luxurious interface afforded by Mac OS. Still others may have been stuck with nothing more than a cell phone, or even just a TI-84 calculator.
Regardless of your humble beginnings, I want to congratulate you on taking things to the next level by jumping headfirst into the world of Linux. Whatever your reason for dipping your toes in these waters, I'm sure you won't regret it! Anyone involved with computers will almost certainly encounter Linux at some point in their career, so now is the time for you to get ahead of things and figure out how to use the dang thing!
All you'll need is a little patience and about 10 minutes to get started! Read on.
Disclaimer: the video is 10 minutes, but the article may be a bit more verbose. :)
In this video, we cover writing to files and discuss "write" mode vs. "append" mode.
In this video, we take a sip out of a file - just a quick skim, printing out the contents.
It's a great skill that we'll build on later.
Any of these examples are editable on CodePen. Just click "Edit on Codepen" in the top right corner and you can make as many changes as you want. Don't worry - the changes you make will be just for you! You don't have to worry about making mistakes, because you can always come back here to start fresh.
Photo by Igor Haritanovich
Click the button below to start the Genie Game!
If you look at the code, you'll notice that we're using
for statements to make this work. These are called control flow statements, and without them, programming would be a lot harder! They let us control which code is executed, allowing us to change what happens based on the answers given by the user (that's you!).
To show messages to the user, we use the
alert function. It's easy to use - all you have to do is follow this format, and you'll see a popup box with your message:
Another function that we used is the
confirm function. It displays a box with a message, just like the
alert function, but it has a special feature. Instead of a single "OK" button, the
confirm box has both an "OK" and a "Cancel" button. If the user presses the "OK" button, a value of
true is returned. On the other hand, if you hit "Cancel," a value of
false is returned. We can use this to ask yes or no questions and change which messages we display based on the responses.
Finally, the last major function that we use is the
prompt function. This is just like the
confirm functions, but it gives you a text box to type in a message to the program. You can use it like this:
With all of that out of the way, let's see it in action! Click the button below to play the game. Then, try changing the code and make it do something new!
As a special challenge, create a new CodePen and try to make your own story from scratch. Be sure to use this one as a reference if you need it.
Let's try out the snippets. Right click on this post and press "Inspect Element." Then, look for the Console. Copy each of the snippets from the beginning of the post and paste them into the Console. For bonus points, change the messages to something that you made up yourself!
Continue the story after the three wishes are granted. You can include any number of
forstatements, if you're feeling adventurous! Hint: Start by adding a new line of code after line #32.
Use the template below to create your own story from scratch! You can start by just replacing the text that is displayed with your own story. Then, try building your own logic.
This code picks a random color when you press the button, and shows you the answer.
If you ever need to pay the bill at a restaurant, you may need to figure out how much to tip. This calculator takes the bill amount you provide and adds 20% so that you know how much to pay!
The HTML Canvas is a special element on the page that lets you draw custom shapes, lines, and images wherever and however you want. It's often used to create games right in your browser. It's a bit of an advanced topic, so we won't delve into it for this post. Try messing around with the code to get a feel for it.
In this video, we keep the user in line! With error handling, we can specify what type of input we're expecting to receive. This basic skill will also be useful for countless other situations as you continue your Python journey.
In this video, we find out how to get user input into our program - a huge advantage if you're just starting out.
In this video, we get our feet wet and unlock a tiny bit of the enormous power Python offer with a simple for loop.
In this video we make sure we have Python 3 installed on our Ubuntu Linux system.