python study guide

24
Question 1 3 out of 3 points The ______________ coding scheme is a worldwide standard for representing the characters of many of the world's languages. Answer Selected Answer: Unicod e Correct Answer: Unicod e Question 2 3 out of 3 points Which computer language uses short words known as mnemonics for writing programs? Answer Selected Answer: Assembl y Correct Answer: Assembl y Question 3 3 out of 3 points Which of the following is not an example of operating system software? Answer Selected Answer: Microsoft Word

Upload: max-potent

Post on 18-Apr-2015

2.285 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Python Study Guide

Question 1

3 out of 3 pointsThe ______________ coding scheme is a worldwide standard for representing the characters of many of the world's languages.Answer

Selected Answer: Unicode

Correct Answer: Unicode

Question 2

3 out of 3 pointsWhich computer language uses short words known as mnemonics for writing programs?Answer

Selected Answer: Assembly

Correct Answer: Assembly

Question 3

3 out of 3 pointsWhich of the following is not an example of operating system software?Answer

Selected Answer: Microsoft Word

Correct Answer: Microsoft Word

Question 4

3 out of 3 pointsPrograms that make a computer useful for everyday tasks are known as ___________.Answer

Selected Answer: Application Software

Page 2: Python Study Guide

Correct Answer: Application Software

Question 5

3 out of 3 pointsWhat is the encoding technique called that is used to store negative numbers in the computer’s memory?Answer

Selected Answer: Twos complement

Correct Answer: Twos complement

Question 6

3 out of 3 pointsThe following is an example of an instruction written in which computer language?

     10100001Answer

Selected Answer: Machine language

Correct Answer: Machine language

Question 7

3 out of 3 pointsA(n) ___________ is a set of instructions that a computer follows to perform a task.

Answer

Selected Answer: program

Correct Answer: program

Question 8

Page 3: Python Study Guide

3 out of 3 pointsThe process known as the ___________ cycle is used by the CPU to execute instructions in a program.Answer

Selected Answer: Fetch-decode-execute

Correct Answer: Fetch-decode-execute

Question 9

3 out of 3 pointsReal numbers are encoded using the ________ technique.

Answer

Selected Answer: floating point

Correct Answer: floating point

Question 10

3 out of 3 pointsWhat is the largest value that can be stored in one byte?Answer

Selected Answer: 255

Correct Answer: 255

Question 11

3 out of 3 pointsUse what you've learned about the binary numbering system in this chapter to convert the binary number (1101) to decimal.

Answer

Selected Answer: 13

Correct Answer: 13

Page 4: Python Study Guide

Question 12

3 out of 3 pointsWhile a program is running, the computer stores the program as well as the data that the program is working with in what part of the computer?

Answer

Selected Answer: main memory

Correct Answer: main memory

Sunday, May 27, 2012 2:41:52 PM EDT

Question 1

2 out of 2 pointsWhich of the following is not a variable data type in Python?Answer

Selected Answer: Number

Correct Answer: Number

Question 2

2 out of 2 pointsWhat type of symbol can be used in Python to mark the beginning and end of a string?Answer

Selected Answer: Quotation

Correct Answer: Quotation

Question 3

0 out of 2 pointsIn the Celsius to Fahrenheit Temperature Converter project, what is the correct method to compute the equivalent fahrenheit temperature?  Assume that the variable celsius contains the original input temperature in degrees Celsius.

Page 5: Python Study Guide

Answer

Selected Answer: # Compute the equivalent temperature in

Fahrenheitfahrenheit = 1.8 celsius + 32

Correct Answer: # Compute the equivalent temperature in

Fahrenheitfahrenheit = 9.0 / 5.0 * celsius + 32

Question 4

2 out of 2 pointsTrue/False: The expressions (a + b) / c  and  a + b / c will always yield identical results.Answer

Selected Answer:

 False

Correct Answer:

 False

Question 5

2 out of 2 pointsTrue/False: In most computer languages, the first character of a variable name cannot be a numeric digit (that is, 0, 1, 2, … 9).Answer

Selected Answer:

 True

Correct Answer:

 True

Question 6

2 out of 2 pointsIn the Total of items in a shopping cart project, what is the correct method to compute the sales tax?  Assume that the variable subtotal contains the correct sum for the five purchased items.

Answer

Selected Answer:

Page 6: Python Study Guide

# compute the sales taxSALES_TAX_RATE = 0.06tax = subtotal * SALES_TAX_RATE

Correct Answer: # compute the sales tax

SALES_TAX_RATE = 0.06tax = subtotal * SALES_TAX_RATE

Question 7

2 out of 2 pointsThe value of the expression 12 – 4 * 3 / 2 + 9 is _________.Answer

Selected Answer: 15

Correct Answer: 15

Question 8

2 out of 2 pointsWhat is the informal language that programmers use to create models of programs that have no syntax rules and are not meant to be compiled or executed?Answer

Selected Answer: Pseudocode

Correct Answer: Pseudocode

Question 9

2 out of 2 pointsThe following is an example of what type of statement:                  Set rate = 5.75

Answer

Selected Answer: Assignment

Page 7: Python Study Guide

Correct Answer: Assignment

Question 10

2 out of 2 pointsA(n) _______________ variable is one that has been declared, but has not been initialized or assigned a value.Answer

Selected Answer: uninitialized

Correct Answer: uninitialized

Question 1

2 out of 2 pointsWhat is the term used for the variable that receives an argument that passed into a module?Answer

Selected Answer: Parameter

Correct Answer: Parameter

Question 2

2 out of 2 pointsPassing an argument by ________ means that only a copy of the argument's value is passed into the parameter variable.Answer

Selected Answer: Value

Correct Answer: Value

Question 3

2 out of 2 pointsIn the Paint Job Estimator project, identify an acceptable headerfor the definition of a Python module used to compute and show the estimate

Page 8: Python Study Guide

of the painting work.

Answer

Selected Answer: def showPaintingEstimate(wall_area,

paint_cost_per_gallon):

Correct Answer: def showPaintingEstimate(wall_area,

paint_cost_per_gallon):

Question 4

2 out of 2 pointsThe following is an example from Python of a module _________________.

    showSalesTaxDue( 110932.0 )

Answer

Selected Answer: Call (or execution)

Correct Answer: Call (or execution)

Question 5

2 out of 2 pointsFunction is another name for _____________.Answer

Selected Answer: Module

Correct Answer: Module

Question 6

2 out of 2 pointsIn the Monthly Sales Tax project, identify acceptable Pythoncode that interactively inputs the monthly sales and passes it asan argument by calling a "sales tax" module.

Page 9: Python Study Guide

Answer

Selected Answer: sales = input("Please enter the monthly sales

(eg, 25000): ")showSalesTaxReport(sales)

Correct Answer: sales = input("Please enter the monthly sales

(eg, 25000): ")showSalesTaxReport(sales)

Question 7

2 out of 2 pointsAccording to the BMI information at the cdc.gov web page

   http://www.cdc.gov/healthyweight/assessing/bmi/adult_bmi/index.html

the BMI is calculated by dividing weight in pounds by heightin inches squared and multiplying by a conversion factor of 703.

Choose the Python code at the COMPLETE THE COMPUTATION commentbelow that gets this correct.

# define a function to compute and display Body Mass Index# citation: #    http://www.cdc.gov/healthyweight/assessing/bmi/adult_bmi/index.html# Parameters:#    weight is in lbs#    height_ft is the WHOLE part of height in feet#    height_in is the FRACTIONAL part of height in remaining inches#def showBodyMassIndex(weight, height_ft, height_in):    # define named constants used by the BMI calculation    BMI_EN = 703.0   # needed to convert from English units to metric    INCHES_PER_FOOT = 12.0     # COMPLETE THE COMPUTATION

Answer

Page 10: Python Study Guide

Selected Answer:     # COMPLETE THE COMPUTATION

    height = height_ft * INCHES_PER_FOOT + height_in    bmi = weight * BMI_EN / (height * height)

Correct Answer:     # COMPLETE THE COMPUTATION

    height = height_ft * INCHES_PER_FOOT + height_in    bmi = weight * BMI_EN / (height * height)

Question 8

2 out of 2 pointsA pass by _________ argument means that the argument is passed into a parameter that will reference (as an alias) the content of the argument in the module.Answer

Selected Answer: Reference

Correct Answer: Reference

Question 9

2 out of 2 pointsWhich type of variable is not recommended to be used in programs because they make programs hard to understand and debug?Answer

Selected Answer: Global

Correct Answer: Global

Question 10

2 out of 2 pointsWhich type of variable is visible to every module and the entire program?Answer

Selected

Page 11: Python Study Guide

Answer: Global

Correct Answer: Global

Saturday, June 23, 2012 2:21:52 AM EDT

What type of operator is used in Python to determine whether a specific relationship exists between two values?  (for example, greater than, less than, equality, etc.)

Answer

Selected Answer: Relational

Correct Answer: Relational

Question 2

2 out of 2 pointsWhich operator is best to determine whether a variable x contains a value in the range of 10 through 57?

Answer

Selected Answer: and

Correct Answer: and

Question 3

0 out of 2 pointsIn the Color Mixer project, if the user enters anything other than a primary color (for example, the color purple), then the program should display an error message. Of the following Python code fragments, identify the correct implementation to detect an invalid color input.

Answer

Selected Answer: c1 = raw_input("Enter a primary color (eg, red,

blue or yellow): ")

Page 12: Python Study Guide

# check that c1 is a primary color, and if not, display an error msgif not( c1 == red or c1 == blue or c1 == yellow ):   print "Sorry, but", c1, "is not a primary color."

Correct Answer: c1 = raw_input("Enter a primary color (eg, red,

blue or yellow): ")# check that c1 is a primary color, and if not, display an error msgif not( c1 == "red" or c1 == "blue" or c1 == "yellow" ):   print "Sorry, but", c1, "is not a primary color."

Question 4

2 out of 2 pointsWhich of the following is a logical (boolean) operator in Python?

Answer

Selected Answer: and

Correct Answer: and

Question 5

2 out of 2 points

In the Shipping Charges project, identify acceptable Python code to handle the third row of the shipping charges table, shown here:

Weight of PackageRate per Pound

2 pounds or less $1.10Over 2 pounds, but not more than 6 pounds

$2.20

Over 6 pounds, but not more than 10 pounds

$3.70

Over 10 pounds $3.80Answer

Page 13: Python Study Guide

Selected Answer: elif weight > 6 and weight <= 10:

   rate_per_lb = 3.7

Correct Answer: elif weight > 6 and weight <= 10:

   rate_per_lb = 3.7

Question 6

2 out of 2 pointsWhich operator is used in Python to determine that the operands are not of the same exact value?

Answer

Selected Answer: !=

Correct Answer: !=

Question 7

0 out of 2 pointsThe _________ operator in Python is a unary operator as it works with only one operand.

Answer

Selected Answer: or

Correct Answer: not

Question 8

2 out of 2 pointsProblem #10 (page 161), the enhanced Body Mass Index (BMI) program, states thata sedentary person's weight is considered to be optimal if his or her BMI is between18.5 and 25. If the BMI is less than 18.5, the person is considered to be underweight.If the BMI value is greater than 25, the person is considered to be overweight.

Page 14: Python Study Guide

Identify the correct Python code fragment for the interpretation of the BMI value:

Answer

Selected Answer: # display the proper message based on the BMI

print "BMI interpretation: ",if (bmi < 18.5):  print "underweight."elif (bmi <= 25):  print "optimal."else:  print "overweight."

Correct Answer: # display the proper message based on the BMI

print "BMI interpretation: ",if (bmi < 18.5):  print "underweight."elif (bmi <= 25):  print "optimal."else:  print "overweight."

Question 9

2 out of 2 pointsWhat type of operators are the following in Python?

   >    <    >=    <=    ==    !=

Answer

Selected Answer: Relational

Correct Answer: Relational

Question 10

2 out of 2 pointsIn the Python example program paycheck_with_if.py, the paycheck is computed using an if else statement. Conditional logic code using if else statements can be replaced with a single if statement, using a

Page 15: Python Study Guide

strategy sometimes called act first, check later. Here that can be applied by first computing the paycheck while assuming either overtime (or no overtime), and then to check the overtime assumption and, if necessary, change the computed paycheck.

Which of the following Python code fragments is a correct implementation of this coding strategy:Answer

Selected Answer: # ------- "act first, check later": an if

else replacement -----------# compute the paycheck, assuming no overtime workpaycheck = wage * hoursif hours > 40:   # overtime paycheck calculation, assumming time-and-a-half for over   # 40 hours of labor   paycheck = 40.0 * wage + (hours - 40) * wage * 1.5   print "Overtime added"

Correct Answer: # ------- "act first, check later": an if

else replacement -----------# compute the paycheck, assuming no overtime workpaycheck = wage * hoursif hours > 40:   # overtime paycheck calculation, assumming time-and-a-half for over   # 40 hours of labor   paycheck = 40.0 * wage + (hours - 40) * wage * 1.5   print "Overtime added"

Instructions

Question 1

2 out of 2 pointsWhat is the term used for the variable that is defined in the header of a module DEFINITION and that receives a value from a module call?

false

Page 16: Python Study Guide

Answer

Selected Answer: Parameter

Correct Answer: Parameter

Question 2

2 out of 2 pointsIn pseudocode, the following is an example of what type of statement:  Set rate = 5.75

Answer

Selected Answer: Assignment

Correct Answer: Assignment

Question 3

2 out of 2 pointsThe following is an example of an instruction written in which computer language?

             10110000Answer

Selected Answer: Machine language

Correct Answer: Machine language

Question 4

2 out of 2 pointsPrograms that make a computer useful for everyday tasks are known as ___________.Answer

Selected Answer: Application Software

Correct

Page 17: Python Study Guide

Answer: Application Software

Question 5

2 out of 2 pointsFirst of all, re-download the chapter ZIP notes for chapter 4. Examine the solution to the Magic Dates project (#4, page 160). The code shows that it's possible to write selection logic for a true/false alternative with either a simple if else statement or by using a programming strategy that I refer to as Act first, check later.

In the following, identify the Python code fragment that correctly implements an Act first, check later strategy to compute the area of a geometric figure. Assume that the variable figure is either the string "rectangle" or the string "triangle", and that the dimensions of the figure are stored in the variables height and base.

Answer

Selected Answer: # assume that the figure is a rectangle

area = height * baseif (figure == "triangle"):    area = 0.5 * height * base

print figure, "has area of", area

Correct Answer: # assume that the figure is a rectangle

area = height * baseif (figure == "triangle"):    area = 0.5 * height * base

print figure, "has area of", area

Question 6

2 out of 2 pointsIn Python, a good statement to use for writing the letter grade example from your textbook  on page 141, Program 4-7, is:Answer

Selected Answer: if elif

Correct

Page 18: Python Study Guide

Answer: if elif

Question 7

2 out of 2 pointsIn the following partial Python program, there is a variable scope mistake that prevents the sales tax calculations from being done.  What is the mistake?

def showSalesTaxReport(monthly_sales):    # define named constants used by the tax calculation    COUNTY_TAX_RATE = 0.02    STATE_TAX_RATE = 0.04

    # do the computations    county_sales_tax = COUNTY_TAX_RATE * sales    state_sales_tax = STATE_TAX_RATE * sales    total_sales_tax = county_sales_tax + state_sales_tax     # display the results

 # define the main function showing the use of the showPropertyTax functiondef main():    sales = input("Please enter the monthly sales (eg, 25000): ")    showSalesTaxReport(sales)

Answer

Selected Answer: The variable sales is local in scope to the main() module, so it

cannot be used as shown in the showSalesTaxReport() module.

Correct Answer: The variable sales is local in scope to the main() module, so it

cannot be used as shown in the showSalesTaxReport() module.

Question 8

2 out of 2 pointsIn a module call, passing an argument by ________ means that only a COPY of the argument's value is passed into the parameter variable.Answer

Page 19: Python Study Guide

Selected Answer: Value

Correct Answer: Value

Question 9

2 out of 2 pointsWhat category of programming statements can be considered a logical design that controls the order in which a set of statements executes?Answer

Selected Answer: Decision

Correct Answer: Decision

Question 10

2 out of 2 pointsWhich error produces incorrect results but does not prevent the program from running?Answer

Selected Answer: logic

Correct Answer: logic