Before you keep reading...
Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.
Before you keep reading...
Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.
2.13. Chapter Exercises¶
==
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.
Add a set of parentheses to the expression x = 6 * 1 - 2
so that the code below prints -6 instead of 4.
Add parentheses to x = 12 * 2 - 3 + 4 * 2
so that it prints -4 instead of 29.
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!
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.
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!