©2020 Pearson Education, Inc., 330 Hudson Street, NY NY 10013. All rights reserved.
Chapter 1: Programming Project 1: (Display three different messages) Write a program that displays Welcome to Python Welcome to Computer Science Programming is fun.
# Exercise01_01 print("Welcome to Python") print("Welcome to Computer Science") print("Programming is fun")
Chapter 1: Programming Project 2: (Compute expressions) Write a program that displays the result of (9.5 * 4.5 - 2.5 * 3) / (45.5 - 3.5).
# Exercise01_05 print((9.5 * 4.5 - 2.5 * 3) / (45.5 - 3.5))
Chapter 1: Programming Project 3: (Population projection)
The US Census Bureau projects population based on the following assumptions:
One birth every 7 seconds One death every 13 seconds One new immigrant every 45 seconds Write a program to display the population for each of the next five years. Assume the current population is 312032486 and one year has 365 days.
# Exercise01_11 print(312032486 + 365 * 24 * 60 * 60 / 7 - 365 * 24 * 60 * 60 / 13 +
365 * 24 * 60 * 60 / 45)
print(312032486 + 2 * 365 * 24 * 60 * 60 / 7 - 2 * 365 * 24 * 60 * 60 /
13 + 2 * 365 * 24 * 60 * 60 / 45)
(Introduction to Python Programming and Data Structures, 1e Daniel Liang) (Solution Manual, For Complete File, Download link at the end of this File) 1 / 4
©2020 Pearson Education, Inc., 330 Hudson Street, NY NY 10013. All rights reserved.
print(312032486 + 3 * 365 * 24 * 60 * 60 / 7 - 3 * 365 * 24 * 60 * 60 /
13 + 3 * 365 * 24 * 60 * 60 / 45)
print(312032486 + 4 * 365 * 24 * 60 * 60 / 7 - 4 * 365 * 24 * 60 * 60 /
13 + 4 * 365 * 24 * 60 * 60 / 45)
print(312032486 + 5 * 365 * 24 * 60 * 60 / 7 - 5 * 365 * 24 * 60 * 60 /
13 + 5 * 365 * 24 * 60 * 60 / 45)
Chapter 1: Programming Project 4: (Simple computation) The formula for computing the discriminant of a quadratic equation ax^2 + bx + c = 0 is b^2 – 4ac.Write a program that computes the discriminant for the equation 3x^2 + 4x + 5 = 0.
# Exercise01_01Extra print(4 * 4 - 4 * 3 * 5)
Chapter 1: Programming Project 5:
(Physics: acceleration)
Average acceleration is defined as the change of velocity divided by the time taken to make the
change, as shown in the following formula:
a = (v1 - v0) / t Here, v0 is the starting velocity in meters/second, v1 is the ending velocity in meters/second, and t is the time span in seconds.Assume v0 is 5.6, v1 is 10.5, and t is 0.5, and write the code to display the average acceleration.
# Exercise01_02Extra print((10.5 - 5.6) / 0.5)
Chapter 2
Quiz 2.5 #1:
Assign 7 to a variable named seven.
seven = 7
Quiz 2.5 #2:
Define a variable precise and make it refer to 1.09388641.
precise = 1.09388641
Quiz 2.5 #3:
Define two variables, one named length making it refer to 3.5 and the other named width making it refer to 1.55.
- / 4
©2020 Pearson Education, Inc., 330 Hudson Street, NY NY 10013. All rights reserved.
length = 3.5 width = 1.55
Quiz 2.6 #1:
Variables i and j each have associated values. Swap them, so that i becomes associated with j's original value, and j becomes associated with is original value. You can use two more variables itemp and jtemp.
Note: This question does not follow our naming convention for
variables. itemp and jtemp should have been named iTemp and jTemp.
itemp = i jtemp = j i = jtemp j = itemp
Quiz 2.6 #2:
Given two already defined variables, i and j, write a statement that swaps their associated values.
i, j = j, i
Quiz 2.6 #3:
Given two variables matric_age and grad_age, write a statement that makes the associated value of grad_age 4 more than that of matric_age.
Note: This question does not follow our naming convention for
variables. matric_age and grad_age should have been named matricAge and gradAge.
grad_age = matric_age + 4
Quiz 2.8 #1:
Given the variables taxable_purchases and tax_free_purchases (which already have been defined), write an expression corresponding to the total amount purchased.
Note: This question does not follow our naming convention for
variables. taxable_purchage and tax_free_purchase should have been named taxablePurchage and taxFreePurchase.
taxable_purchases + tax_free_purchases
Quiz 2.8 #2:
Given the variables full_admission_price and discount_amount (already defined), write an expression corresponding to the price of a discount admission.
full_admission_price - discount_amount
Quiz 2.8 #3:
Given the variable price_per_case, write an expression corresponding to the price of a dozen cases. 3 / 4
©2020 Pearson Education, Inc., 330 Hudson Street, NY NY 10013. All rights reserved.
Note: This question does not follow our naming convention for
variables. price_per_case should have been named pricePerCase.
price_per_case * 12
Quiz 2.8 #4:
Given the variables cost_of_bus_rental and max_bus_riders, write an expression corresponding to the cost per rider (assuming the bus is full).
cost_of_bus_rental / max_bus_riders
Quiz 2.8 #5:
Write an expression that computes the remainder of the variable principal when divided by the variable divisor. (Assume that each is associated with an int.)
principal % divisor
Quiz 2.8 #6:
Write an expression that computes the average of the values 12 and 40, and assign it to the variable avg, which has already been defined.
avg = (12 + 40) / 2
Quiz 2.8 #7:
You are given two variables, both already defined. One is named price and is associated with a float and is the price of an order. The other is total_number and is associated with an int and is the number of orders. Write an expression that calculates the total price for all orders.
price * total_number
Quiz 2.8 #8:
You are given two variables, both already defined, one associated with a float and named total_weight, containing the weight of a shipment, the other associated with an int and named quantity, containing the number of items in the shipment. Write an expression that calculates the weight of one item.
total_weight / quantity
Quiz 2.8 #9:
Assume there is a variable, h already assigned a positive integer value. Write the code necessary to assign its square to the variable g. For example, if h had the value 8 then g would get the value 64.
g = h * h
Quiz 2.8 #10:
Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Assuming the item is paid for with a minimum amount of change and just single dollars, write an expression for the amount of change (in cents) that would have to be paid.
- / 4