Welcome back to my blog! Now we are going to start adding Python to our repertoire. I hope you stay with me for this brief look into a simple Python code to generate a Brand Name. But before we get started, I want to make sure that you know what Python is, what it is used for and also how to download it to your OS so that you can follow along with me.
*Before we get started, any word that is underlined in this blog is a link directly to the source material for further reading and understanding
What is Python and what is it used for? Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together.
Now that we have the definition out of the way, let’s go over how to add Python to your environment. We can do this in a couple different ways depending on the OS that you choose to use but I personally recommend installing Homebrew to your CLI which brings us to the next question…
What is Homebrew and what is it used for? Homebrew is a free and open-source software package management system that simplifies the installation of software. Homebrew can be downloaded and used on MacOS, Linux as well as Windows 10. In my opinion, this is the easiest way to download anything to your CLI.
Once you have Homebrew installed, getting Python is as easy as typing in the following command: $ brew install firstname.lastname@example.org
However, if you are running on an earlier version of Windows, to get Python installed you will have to install Chocolatey and then install Python using the following walkthrough: Hitchhikers Guide To Python.
Once you have Python installed, we can now start on our project.
Step 1: Get into the Python environment
Alright, let’s go ahead and get this party started. Run the command “python3” in your CLI to get into the Python environment. You will know that you are there due to the “>>>” arrows.
Step 2: Create A Greeting
Once you figure out your greeting, place it in the quotation marks inside of the parentheses. This tells Python exactly what you want your name to appear as when it prints it to the screen.
Step 3: Generate your questions
Here you will begin creating the questions that you would like to be answered. Also, keep the order you would want them to be printed back to you in mind. The questions that I personally chose are below:
- Ask the user for the city that they grew up in-
city = input(“What’s name of the city you grew up in?\n”)
2. Ask the user for the name of a pet-
pet_name = input(“What’s your pet’s name\n”)
3. Combine the name of their city and pet and also show them their band name-
print(“Your band name could be “ + city + “ “ + pet_name)
Here is where you will see my mistakes, lol. Make sure there is a space at the beginning of the quotes and the addition sign. Also make sure that the rest of the command is appropriately spaced out to avoid Python joining your answers together.
A couple of things to keep in mind while using Python:
- Numbers cannot be used in front of variables. For example 1variable is not allowed where as variable1 is.
- A _ should be used between words so that Python reads it correctly. Ex- pet_name
- An example of combining a variable is the command that we entered- print(“Your band name could be “ + city + “ “ + pet_name)
- An example of creating a variable is the above command that we entered- city = input(“What’s name of the city you grew up in?\n”)
- \n begins a new line in your output. Ex-
This concludes my first Python lab. I hope you guys stay with me for more!