How the Computer Affects Programming

The relationship between hardware and software

You will find that the hardware of the computer itself determines the design of languages, such as Python. Consider a typical computer that you buy online.

images/ComputerHW.png

You typically specify, the following components:

There are often other choices buying a computer, such as a specialized CPU for handling graphics, called a GPU, and such. When you buy a computer, you typically balance the cost against the speed of the CPU, the amount of memory and disk space, keyboard and mouse/track pad features, and the size and quality (resolution) of the screen. Although the programmer must take this into account for some apps, especially games, initially you won’t need to concern yourself with the performance of your software on different hardware configurations.

If you are buying a cell phone, you will also see the hardware similarities. The phone has a CPU that affects the speed of apps running on it, memory for apps and more memory for disk-like capabilities for storing data like pictures, music, and such, a keyboard for input, a screen for output, which you can also touch to provide input and gestures, and of course access to the internet via wifi or cellular.

The reason to introduce the relationship between hardware and a computer language and an app you code with it, is to identify how the language interacts with the computer:

images/ComputerOrganization.png

There are a couple of syntax items not yet mentioned: input() and print() are built-in functions in Python. A function is a series of statements that perform an action. You won’t need to know the messy details of how to interact with the hardware to print or accept input because you can use the built-in function instead. The int() statement is also a function that takes the returned value, of input() in this case, and converts it to a number (integer)–data types like integer and string will be discussed in much more detail.

Assignment

  1. Take the examples in this section and add them to your HelloWorld project. (See Starting Code below.) Remember, in Python, indentation of code is very important so you need to start with the code below and keep your code aligned in a block. (See Python Syntax for Python Indentation information.)
  2. Review the Python Variable tutorial at w3schools.com and experiment. Don’t worry about the things that haven’t been introduced yet.
  3. Extra credit: Review the Python User Input tutorial. Improve the program so the user knows which value s/he is entering.

Submit a screen shot of your IDE after you run your code and answer the following questions:

  1. What part of the computer must an instruction be in before it can be executed?
  2. What part of the computer must a variable be stored before it can be accessed by the CPU?
  3. What is the difference between a variable and a value?
  4. What does the assignment operator do?
  5. What is a constant?

Starting Code

if __name__ == "__main__":
    print("Hello World!")
    # your code goes here