Skip to main content

Exercises 1.15 Exercises

1.

    Q-1: What is the function of the secondary memory in a computer?
  • Execute all of the computation and logic of the program
  • This would be correct if we asked what the CPU does.
  • Retrieve web pages over the Internet
  • This would be correct if we asked what the client does.
  • Store information for the long term, even beyond a power cycle
  • The secondary memory provides long term storage, even if you turn off the computer.
  • Take input from the user
  • The secondary memory does not ask users for input.

2.

    Q-2: When talking about computers and code, which of the following is a program?
  • A set of instructions for your computer and CPU.
  • A program holds the instructions that answer the CPU's "What next" question.
  • The process of creating and editing code.
  • Programming is the process of creating and editing these instructions.
  • An event that teaches you to write code.
  • This can be a program, but not the kind we're talking about here.
  • A question you ask your computer.
  • While a program can ask your computer or the user a question, it typically answers the question of "what next" from your CPU.

3.

Q-3: A __________ is a program that can analyze and execute a program line by line.

4.

    Q-4: Which of the following creates or contains “machine code”?
  • The Python interpreter
  • The interpreter translates python source code from a human readable form to machine code
  • The keyboard
  • The keyboard provides textual input
  • A Python source file
  • The Python source file contains human readable programs
  • A word processing document
  • A word processing document contains text

5.

    Q-5: Where in the computer is a variable such as “x” stored after the following Python line executes?
    x = 123
    
  • Central processing unit
  • The CPU processses instructions
  • Main Memory
  • The main memory holds the values of the variables while a program executes
  • Secondary Memory
  • Secondary memory provides long-term storage. You must write out values to secondary memory to store them long-term.
  • Input Devices
  • Input devices do not store data
  • Output Devices
  • Ouptut devices do not store data

6.

    Q-6: What will the following program print out:
    x = 43
    x = x + 1
    print(x)
    
  • 43
  • The value of x was changed.
  • 44
  • While x was set to 43 originally it was changed to one more than the current value.
  • x + 1
  • This would be true if the code was priInput devices do not store data
  • Error because x = x + 1 is not possible mathematically
  • This code sets the value of x to the current value of x plus 1.

7.

    Q-7: Pick the best replacements for 1 and 2 in the following sentence: When comparing compilers and interpreters, a compiler is like 1 while an interpreter is like 2.
  • 1 = a process, 2 = a function
  • Compiling is a software process, and running the interpreter is invoking a function, but how is a process different than a function?
  • 1 = translating an entire book, 2 = translating a line at a time
  • Compilers take the entire source code and produce object code or the executable and interpreters execute the code line by line.
  • 1 = software, 2 = hardware
  • Both compilers and interpreters are software.
  • 1 = object code, 2 = byte code
  • Compilers can produce object code or byte code depending on the language. An interpreter produces neither.

8.

Q-8: A brain is the human equivalent to what in your computer?

9.

Q-9: A keyboard is an example of an Input or Output device?

10.

Q-10: A speaker is an example of an Input or Output device?

11.

Q-11: The Python interpreter or complier will tell you if your code has a __________ Error.

12.

Try running the following code. Can you tell what is wrong with it and fix it?
Solution.
# The print function is spelled incorrectly
# and needs parentheses around its contents
print('Hello world!')