COMP1405/1005是一门面向留学生的计算机编程入门课程,旨在教授计算机编程的基本概念和技能。本课程涵盖编程语言、程序设计、数据结构等多个方面,通过理论讲解和编程实践等多种教学方式,培养学生的计算机编程思维和实践能力。
COMP 1405/1005 (Winter 2023) − "Introduction to Computer Science I"
Practice Questions for Quiz 1
You are NOT permitted to post this document online.
You are NOT permitted to share this document with anyone.
This document was designed to help you prepare for the first of your quizzes in COMP 1405/1005.
Before proceeding any further, watch the video and read the step-by-step guide available online at:
https://carleton.ca/brightspace/students/taking-quizzes/
The actual quiz is 1.0 hours in duration and will be available to you (as a Brightspace activity) over
a 48-hour period. You are advised to complete the quiz as early as possible, to reduce the likelihood
of technical complications. In the event of a technical issue, immediately contact your instructor
at robert.collier@scs.carleton.ca or connorhillen@cunet.carleton.ca, including your name, student
number, and a brief description of the issue, and then complete the quiz if you are able to do so.
For this quiz, we will use the "honour system", meaning that you must complete the quiz individually,
without collaboration or unauthorized aids. You may use the virtual machine to test any of your
programs if you wish, but the questions have been designed such that this should not be necessary. You
are not permitted to communicate with anyone, use the internet for any reason, or refer to your
notes during the quiz.
Question 1: "Geometric Solid Calculation"
For this question you will design and implement a program that starts by asking the user for the
radius of the outer surface, the radius of the inner surface, and the height of a hollow cylinder. The
values that the user provides can be either integers or floating-point values, and your program must
then compute the volume and display the result. To compute the volume of a hollow cylinder, you
start by computing the square of the radius of the outer surface and then subtract from that the
square of the radius of the inner surface. You then multiply this result by the height of the cylinder,
and then multiply that result by pi.
The result must be displayed on the terminal to a precision of 4 decimal places, and you must use
an "f-string" (i.e., a formatted string literal) to accomplish this - you are not permitted to use any
rounding functions. (n.b., f-strings were not discussed in class but were part of one of your many
mandatory reading assignments)
Do not import any libraries and use a value of 3.14159 for pi.
With this question, I am attempting to assess…
if you understand data types and can prepare user input for processing
if you can translate a series of instructions using the "pipeline" design pattern
if you know how to use the arithmetic operators in Python
if you can use f-strings (which appeared in a mandatory reading assignment)
COMP 1405/1005 (Winter 2023) − "Introduction to Computer Science I"
Practice Questions for Quiz 1
Question 2: "Logical Evaluation"
For this question you must evaluate the result of this circuit if inputs A, B, C, F, and G each have a
value of False, and inputs D, E, and H each have a value of True.
For this question you must evaluate the result of this circuit if inputs D and E each have a value of
False, and inputs A, B, C, F, G, and H each have a value of True.
n.b., You will encounter five (not two) such questions during the actual quiz.
With this question, I am attempting to assess…
if you can recognize the circuit schematic symbols for AND, OR, and NOT
if you can evaluate logic operations (i.e., conjunction, disjunction, and negation)
if you know how to perform a "reduction" (i.e., evaluate a complex expression)
COMP 1405/1005 (Winter 2023) − "Introduction to Computer Science I"
Practice Questions for Quiz 1
Question 3: "Guessing Game"
For this question you will implement a program for playing a guessing game with the user. Your
program will first ask the user to choose one of following words:
SOLITUDE, SNYDER, STARDOM, CALUMNY, SHROUD, or DESTROY.
Your program must then ask the user "yes-or-no" questions using the exact nested branching
structure defined in the image below. You may use "IF-ELIF-ELSE" blocks, if you wish. You can
assume that the user will always answer either "yes" or "no", but they may provide their answer
using either all uppercase or all lowercase letters (so your program must be able to handle both).
You must not ask questions unnecessarily, so do not ask all of your questions at the beginning of the
program. Once your program has determined the word that was selected by the user, the program
must print it out before terminating.
You will need to use the input function to complete your program.
With this question, I am attempting to assess…
if you can interpret an algorithm presented to you as a flowchart
if you can construct a complex nested branching structure
if you can handle variation in the strings provided as user input
COMP 1405/1005 (Winter 2023) − "Introduction to Computer Science I"
Practice Questions for Quiz 1
Question 4: "Precondition Loop"
For this question you must design and implement a precondition loop in Python that will display
the following numbers (one on each line) to the terminal.
11, 17, 23, 29, 35, 41, 47, 53, 59, 65, 71, 77, 83, 89, 95, 101, 107, 113
Although a counter-controlled loop is ideal for this task, you are not permitted to use a FOR loop in
your program - you must use a precondition loop that has been implemented using WHILE instead.
Question 5: "Postcondition Loop"
For this question you must design and implement a postcondition loop in Python that will display
the following numbers (one on each line) to the terminal.
18, 23, 28, 33, 38, 43, 48, 53, 58, 63, 68, 73, 78, 83, 88, 93, 98
Although a counter-controlled loop is ideal for this task, you are not permitted to use a FOR loop in
your program - you must use a postcondition loop that has been implemented using WHILE instead.
Furthermore, your postcondition loop must be implemented using a BREAK statement.
For this question you must design and implement a postcondition loop in Python that will display
the following numbers (one on each line) to the terminal.
19, 25, 31, 37, 43, 49, 55, 61, 67, 73, 79, 85
Although a counter-controlled loop is ideal for this task, you are not permitted to use a FOR loop in
your program - you must use a postcondition loop that has been implemented using WHILE instead.
Furthermore, your postcondition loop must be implemented using a Boolean flag variable.
n.b., You will encounter only one of the two variants of this question during the actual quiz.
With these questions, I am attempting to assess…
if you know the differences between precondition and postcondition loops
if you can implement a postcondition loop using both break and a Boolean flag
if you can design a looping structure that exhibits specific behaviour
COMP 1405/1005 (Winter 2023) − "Introduction to Computer Science I"
Practice Questions for Quiz 1
Question 6: "Nested Loops"
For this question, you will use two pairs of nested counter-controlled loops (i.e., FOR loops) in order
to draw a particular pattern of symbols onto a pygame window.
Your program will need to create a square pygame window of dimensions 750 × 750, and it will
need to update the display for the user and wait for exactly 5 seconds before terminating.
Your program does NOT need to produce the gridlines or the row and column numbers.
You can assume that you have been provided with the following functions:
star(i, j, r, g, b)
- which draws a star on the grid at row i, column j, using the colour (r, g, b)
umbrella(i, j, r, g, b)
- which draws an umbrella on the grid at row i, column j, using the colour (r, g, b)
With this question, I am attempting to assess…
if you know how a colour can be represented using an ordered triple of three integers
if you know how to nest looping control structures
if you know how to configure range function arguments to yield specific behaviour
if you can perform basic operations using pygame