[go: up one dir, main page]

0% found this document useful (0 votes)
36 views5 pages

Checkpoints Chapter 2

Uploaded by

metlos301
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views5 pages

Checkpoints Chapter 2

Uploaded by

metlos301
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Chapter 2

Input, Processing, and Output


Checkpoints
2.1 Who is a programmer’s customer?

Ans: Any person, group, or organization that is asking you to write a


program.

2.2 What is a software requirement?

Ans: A single function that the program must perform in order to


satisfy the
customer.

2.3 What is an algorithm?

Ans: A set of well-defined logical steps that must be taken to


perform a task.

2.4 What is pseudocode?

Ans: An informal language that has no syntax rules and is not meant
to be
compiled or executed. Instead, programmers use pseudocode to
create
models, or “mock-ups,” of programs.

2.5 What is a flowchart?

Ans: A diagram that graphically depicts the steps that take place in
a program.

2.6 What do each of the following symbols mean in a flowchart?


• Oval
• Parallelogram
• Rectangle

Ans: Ovals are terminal symbols. Parallelograms are either output


or input
symbols. Rectangles are processing symbols.
2.7 Write a statement that displays your name.

Ans: print(‘Samya Ayaz’)

2.8 Write a statement that displays the following text:


Python's the best!

Ans: print("Python's the best!")

2.9 Write a statement that displays the following text:


The cat said "meow."

Ans: print('The cat said "meow"')

2.10 What is a variable?

Ans: A name that references a value in the computer's memory.

2.11 Which of the following are illegal variable names in Python, and why?
x
99bottles
july2009
theSalesFigureForFiscalYear
r&d
grade_report

Ans: 99bottles is illegal because it begins with a number. r&d is


illegal because
the & character is not allowed.

2.12 Is the variable name Sales the same as sales? Why or why not?

Ans: No, it is not because variable names are case sensitive.

2.13 Is the following assignment statement valid or invalid? If it is invalid,


why?
72 = amount

Ans: It is invalid because the variable that is receiving the


assignment (in this case
amount) must appear on the left side of the = operator.

2.14 What will the following code display?


val = 99
print('The value is', 'val')

Ans: The value is val.

2.15 Look at the following assignment statements:


value1 = 99, value2 = 45.9, value3 = 7.0, value4 = 7, value5 = 'abc'
After these statements execute, what is the Python data type of the values
referenced by each variable?

Ans: value1 will reference an int. value2 will reference a float.


value3 will reference a float. value4 will reference an int.
value5 will reference an str (string).

2.16 What will be displayed by the following program?


my_value = 99
my_value = 0
print(my_value)

Ans: This will Print 0

2.17 You need the user of a program to enter a customer’s last name. Write a
statement
that prompts the user to enter this data and assigns the input to a variable.

Ans: last_name = input("Enter the customer's last name: ")

2.18 You need the user of a program to enter the amount of sales for the
week. Write a
statement that prompts the user to enter this data and assigns the input to a
variable.

Ans: sales = float(input('Enter the sales for the week: '))

2.19 Complete the following table by writing the value of each expression in
the Value
Expressions Values column:
6+3*5 21
12 / 2 − 4 2
9 + 14 * 2 − 6 31
(6 + 2) * 3 24
14 / (11 − 4) 2
9 + 12 * (8 − 3) 69
2.20 What value will be assigned to result after the following statement
executes?
result = 9 // 2

Ans: 4

2.21 What value will be assigned to result after the following statement
executes?
result = 9 % 2

Ans: 1

2.22 How do you suppress the print function’s ending newline?

Ans: If you do not want the print function to start a new line of
output when it
finishes displaying its output, you can pass the special argument
end = ' '
to the function.

2.23 How can you change the character that is automatically displayed
between
multiple items that are passed to the print function?

Ans: You can pass the argument sep= to the print function,
specifying the
desired character.
2.24 What is the '\n' escape character?

Ans: It is the newline escape character.

2.25 What does the + operator do when it is used with two strings?

Ans: It is the string concatenation operator, which joins two strings


together.

2.26 What does the statement print(format(65.4321, '.2f')) display?

Ans: 65.43

2.27 What does the statement print(format(987654.129, ',.2f')) display?

Ans: 987,654.13
2.28 What are three advantages of using named constants?

Ans: (1) Named constants make programs more self-explanatory, (2)


widespread
changes can easily be made to the program, and (3) they help to
prevent the
typographical errors that are common when using magic numbers.

2.29 Write a Python statement that defines a named constant for a 10


percent discount.

Ans: DISCOUNT_PERCENTAGE = 0.1

You might also like