1.15. Exercises¶
- 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.
Q-1: What is the function of the secondary memory in a computer?
- 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.
Q-2: When talking about computers and code, which of the following is a program?
- 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
Q-4: Which of the following creates or contains “machine code”?
- 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
Q-5: Where in the computer is a variable such as “x” stored after the following Python line executes?
x = 123
- 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.
Q-6: What will the following program print out:
x = 43
x = x + 1
print(x)
- 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.
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.
Try running the following code. Can you tell what is wrong with it and fix it?
You have attempted of activities on this page