Skip to main content
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
Engineering LibreTexts

1.1: Background

( \newcommand{\kernel}{\mathrm{null}\,}\)

Learning Objectives

By the end of this section you should be able to

  • Name two examples of computer programs in everyday life.
  • Explain why Python is a good programming language to learn.

Computer programs

A computer is an electronic device that stores and processes information. Examples of computers include smartphones, tablets, laptops, desktops, and servers. Technically, a program is a sequence of instructions that a computer can run. Programs help people accomplish everyday tasks, create new technology, and have fun.

The goal of this book is to teach introductory programming and problem solving. Writing programs is a creative activity, inherently useful, and rewarding! No prior background in computer science is necessary to read this book. Many different types of programs exist, as shown in the illustration below. This book will focus on general purpose programs that typically run "behind the scenes."

Checkpoint: Online music streaming
Concepts in Practice: Computers and programs
1.
How many types of programs were described in the animation?
  1. 3
  • 4
  • 5
  • 2.
    What type of program will this book explain how to write?
    1. a tool that summarizes an individual's music preferences
    2. a mobile app for managing and sharing playlists of songs
    3. a website that shows the top artists for the past five years
    3.
    Which of the following devices is an example of a computer?
    1. wired headphones that plug into a smartphone
    2. remote control that pauses or skips the current song
    3. wi-fi speaker that streams music from Amazon
    4.
    Reading this book requires a strong background in mathematics.
    1. true
    2. false
    Exploring further

    Later chapters of this book show how to write analysis programs using real data. Example libraries that provide access to online streaming services include Spotipy, Pytube, and Pydora. Python-related tools often have the letters "py" in their name.

    The Python language

    This book introduces Python, one of the top programming languages today. Leading tech giants like Google, Apple, NASA, Instagram, Pixar, and others use Python extensively.

    One reason why Python is popular is because many libraries exist for doing real work. A library is a collection of code that can be used in other programs. Python comes with an extensive Standard Library for solving everyday computing problems like extracting data from files and creating summary reports. In addition, the community develops many other libraries for Python. Ex: Pandas is a widely used library for data analysis.

    Another reason why Python is popular is because the syntax is concise and straightforward. The syntax of a language defines how code must be structured. Syntax rules define the keywords, symbols, and formatting used in programs. Compared to other programming languages, Python is more concise and straightforward.

    Example 1.1

    Hello world in Python and Java

    By tradition, Hello World is the first program to write when learning a new language. This program simply displays the message "Hello, World!" to the user. The hello world program is only one line in Python:

    print("Hello, World!")

    In contrast, the hello world program is five lines in Java (a different language).

    public class Hello {
      public static void main(String[] args) {
       System.out.println("Hello, World!");
      }
    }
    

    However, conciseness is not the only consideration for which language is used. In different situations different languages may be more appropriate. Ex: Java is often used in Android development.

    Checkpoint: Counting lines in a file
    Concepts in Practice: Python vs Java syntax
    5.
    In general, Python programs are _____ than Java programs.
    1. faster
  • longer
  • shorter
  • 6.
    In the example programs above, what syntax required by Java is not required by Python?
    1. semicolons
    2. parentheses
    3. quote marks
    Try It: Favorite song

    The program below asks for your name and displays a friendly greeting. Run the program and see what happens. In the error message, EOF stands for End of File.

    • Many of the programs in this chapter expect input from the user. Enter your name in the Input box below the code. Run the program again, and see what changes.
    • Copy the following lines to the end of the program:

      song = input()
      print("Cool! I like", song, "too.")
      print("What is your favorite song?") song = input() print("Cool! I like", song, "too.")

    • The modified program reads two lines of input: name and song. Add your favorite song to the Input box below your name, and run the program again.

    The next section of the book will explain how print() and input() work. Feel free to experiment with this code until you are ready to move on.


    This page titled 1.1: Background is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by OpenStax via source content that was edited to the style and standards of the LibreTexts platform.

    • Was this article helpful?

    Support Center

    How can we help?