11.9. Chapter Exercises

The code below is supposed to set the price to 1.5 if the weight is less than 2 and otherwise set it to 1.3. It then calculates the total be multiplying the weight by price.

Fix 3 errors with indention in the code below so that it calculates the right total for a weight of 0.5 (the answer should be 0.75). You will not pass the tests yet.

Then change the weight to be 3 and run the program again to pass the tests (answer now should be 3.9).

Write code to complete the isEven function. It should return True if number is even and False if it is odd.

Make sure to return False or True, not "False" or "True" with quotes. False in Python means False/no/0. "False" means “the word False”. True in Python means True/yes/1. "True" means “the word True”.

To check if a number is even, you can divide it by 2 and look at the remainder. (Remember that x % 2 says “divide x by 2 and get the remainder”.) If the remainder is 1, the number is odd. If the remainder is 0, it is even.

Write code to complete the calculatePay function. It takes in a number of hours worked and an hourly pay. If the hours worked is less than 40, it should just return the hours times the hourly pay. If more than 40 hours were worked, the person should earn normal pay for 40 hours and 1.5 times the normal pay for the hours over 40. So if someone worked 50 hours, at $18 per hour they would recieve \(40 \cdot 18 + ((50 - 40) \cdot 18) \cdot 1.5\)

The number of credits someone has determines what class level they are at a University. A Senior has taken 135 or more credits. A Junior hasn’t taken that many, but has taken at least 90 credits. A Sophomore has taken at least 45. A First Year is anyone who has taken 45 or less.

Write code to complete the getClass function. Your code should use credits and the above logic to change classLevel to the appropriate value: either "Senior", "Junior", "Sophomore", or "First Year".

Make sure to change the variable, not just print out the answer!

You have attempted of activities on this page