Skip to main content

Exercises 14.13 Chapter Exercises

1.

== is an operator that checks for equality. If the value on the left side is equal to the value on the right side, it gives True. Otherwise it gives False.
Insert the correct operators in place of the #’s so each line prints True. Don’t change any of the numbers.

2.

Add a set of parentheses to the expression x = 6 * 1 - 2 so that the code below prints -6 instead of 4.

3.

Add parentheses to x = 12 * 2 - 3 + 4 * 2 so that it prints -4 instead of 29.

4.

Complete the code on lines 3 and 5 below to print the cost of a car trip of 500 miles when the car gets 26 miles per gallon and gas costs 3.45 a gallon.
The answer you get should be 66.34615384615385. But make sure you calculate it, as opposed to hardcoding that value into your program!

5.

It is currently 10:00, complete the code to tell what time it is going to be in 18 hours (using 12-hour time, not 24-hour time). Use the % (modulo or remainder operator) to calculate the correct value for clockTime based on the newTime value that is already calculated.
The answer should be 4 because 28 hours divided into 12-hour chunks leaves a remainder of 4. But make sure not to hardcode the answer - you need to calculate the value, not just type it in.

6.

Finish the code on lines 2 and 3 in the code below to print how many hours and minutes you have been waiting when you have been waiting a total of 270 minutes.
Use the % (modulo or remainder operator) and the integer division operator // to calculate the correct values for numHours and numMinutes based on the totalMinutes value.
The correct answers should be 4 for numHours and 30 for numMinutes. But make sure to calculate those values - don’t hardcode them!
You have attempted of activities on this page.