Liner Notes
Sample answers to "Check Yourself…" questions
When you buy an album on vinyl, the liner notes (or "jacket notes") are the information that’s printed on the back of the sleeve or, for music on CD or cassette, in a booklet inside the plastic case. Basic liner notes are just the song titles, and the names of the artists and producers. But sometimes you get lucky, and the liner notes have blurbs written by the artists, or maybe even the complete lyrics to the songs. In other words, a cheat sheet that really helps you understand the music.
These liner notes have answers and basic explanations to the Check Yourself… questions from the chapters. These aren’t meant to be comprehensive answers, just a little information so you can confirm you’re…well, I hate to say it, but…on the right track.
The review questions are intended to be a little open-ended, so your answers will vary from these.
Sound Check
-
What tools do you need to develop Python programs?
You’ll need an IDE and the Python installation package.
-
What does IDE stand for and what is its role in software development?
IDE stands for Integrated Development Environment. It’s the software you’ll use to write your C# code.
-
What IDE did you choose? Why?
Anything is fine, as long as it supports Python! Popular choices include JetBrains PyCharm, Visual Studio Code, eclipse, and many others.
1. Computers and Coding
-
What is the primary role of a programming language in the context of computer programming?
The primary role of a programming language is to act as a bridge between human language and machine language. It allows humans to write instructions in a way that is easier for them to understand and use, which can then be accurately translated into machine language that a computer can execute.
-
What happens when you run a Python program? Describe that process in simple terms.
When you run a Python program, the Python interpreter reads you source code line by line, translates it into machine language, and executes the instructions before moving on to the next line. The repeats until the program is finished.
-
What is PEP-8
PEP-8 is the official style guide for Python code. It specifies the conventions we should use for formatting our code so that it is consistent and easy to read.
-
How would you explain what a “program” is to an 8-year-old?
A program is like a list of instructions you give to a computer—kind of like a recipe. The computer follows the steps exactly to do something, like showing a message or solving a puzzle.
-
Explain the difference between compiled and interpreted programming languages. Which is Python?
Compiled languages are translated into machine language by a compiler before the program is run. This machine language file can then be executed directly by the computer. Interpreted languages are translated into machine language on the fly, as the program is running, by an interpreter.
Python is an interpreted language.
2. Variables and Data Types
-
What are variables, and what are they used for?
Variables are named locations in memory that store data. They are used to hold information that can be used and manipulated in a program.
-
How do you create a variable in Python? Give a simple example.
You create a variable in Python by using an assignment statement, which assigns a value to a name/identifier. For example:
beatlemania_year = 1964creates a variable namedbeatlemania_yearand assigns to it the numeric value1964. -
What is the difference between an integer (
int) and a floating-point number (float)?An
intis a whole number without a decimal point, such as7,18, and-24. Afloatis a number that can have a decimal point, such as3.14. Floats can represent fractional values, while integers cannot. -
Write a line of Python code that creates a variable to store the volume level and sets it to 11 (à la Spinal Tap).
volume_level = 11 -
Explain the use of the
str()function in output. When would you need to use it?The
str()function converts a value to a string. You would need to use it when concatenating a numeric value (like anintorfloat) with a string. -
Write a line of code that calculates 4 to the power of 4 and puts the result in a variable.
result = 4 ** 4 -
What will the following code print? Why?
tracks = 5 bonus = tracks + 3 tracks = 10 print(bonus)The output will be
8because the variablebonusis calculated using the value oftracksat the time of the calculation, which is5. Changingtracksto10after the calculation does not affect the value ofbonus. -
Explain the difference between
/and//in Python./is the division operator that performs floating-point division, which means it will return a decimal result even if both operands (values) are whole numbers. For example,4 / 2will return2.0.//is the floor division operator that performs integer division, which means it will return the whole number part of the division result, discarding any decimal portion. For example,5 // 2will return2rather than2.5. -
Which of the following variable names are invalid? Explain why.
4_lads_from_liverpool shows_in_1963 side_a_tracks! sideBTracks volume%_of_100 supremes_members smokey-robinson-hits blues_with_12_barsThe following variable names are invalid:
-
4_lads_from_liverpoolis invalid because variable identifiers can’t start with a number. -
side_a_tracks!is invalid because variable identifiers can’t contain special characters like!. -
volume%_of_100is valid because variable identifiers can’t contain special characters like%. -
smokey-robinson-hitsis invalid because variable identifiers can’t contain special characters like-.
-
-
Explain the difference between concatenation and interpolation for variable output in Python. Which do you prefer, and why?
Concatenation is the process of joining strings together using the
+operator:singer_name = "Freddie Mercury" band_name = "Queen" print(singer_name + " was the lead singer of " + band_name + ".")Interpolation is the process of embedding variables directly into string using f-strings:
singer_name = "Freddie Mercury" band_name = "Queen" print(f"{singer_name} was the lead singer of {band_name}.")