Chapter 12 Exercises¶
Fix 3 syntax errors in the code below so that it correctly prints “x is less than 3” and then “All done” when x is less than 3.
The code currently prints “Hello” when the number is less than 3. Change it so that it prints “Hello” when the number is equal to 3.
Fix the indention in the code below to use a price of 1.45 if the weight is less than 1 and a price of 1.15 otherwise. There is also one syntax error.
Fill in line 1 with a weight that will make the total equal 1, and fix the indentation errors.
Fix 3 errors with indention in the code below to correctly set the price to 1.5 if the weight is less than 2 and otherwise set it to 1.3.
The code currently does not do anything if the number is equal to 2. Fix it so that it prints “Hey” if the number is 2.
Fix 4 errors in the code below to print “x is a number from 1 to 10” when x is greater than or equal to 1 and less than or equal to 10.
The following code prints “This is not 8” when the number is not 8. Change the if statement, so that it does the same thing but only uses one expression (No “and” or “or”).
Finish the conditional on line 3 to print “You can go out!” if either cleanedRoom or finishedHomework is true (not 0). It should always print “All done” as well.
Complete the conditional and fix the errors so that it prints “Good job” when the number is between 1 and 10 (inclusive) or is 15 and “Fail” when it is not.
Fix 5 errors in the following code to set the price to 1.45 if the weight is less than or equal to 1 and otherwise set it to 1.15.
Fix the indentation below, so that the code sets the price based off the weight, then checks if the total is greater than the amount in your wallet.
Change 3 lines in the code below to correctly set the grade so that a 90 and above is an A, 80-89 is a B, 70 - 79 is a C, 60-69 is a D and below 60 is an E.
Fix the errors in the code, and change it, so there’s only 1 if statement. The code should print “The number is 5” when the number is 5, and should print “The number is NOT 5” when it is not.
Fix 5 errors in the following code to set price to 1.45 if weight is less than 1 and otherwise set it to 1.15.
Complete and finish the code on lines 1 and 4 so that the code prints “Hi”.
Write a procedure that will print out “even” if the passed value is even and “odd” if the passed value is odd. Test both possibilities.
Write a procedure that takes 2 ints, total price, and amount in wallet. Print “You have enough money” if the difference between the wallet and price is 0 or greater; otherwise, print “Get more money”
Write a function that takes a number for a grade and returns a string grade. It should return E for any value below 60, D for 61 to 69, C for 70 to 79, B for 80 to 89 and A for 90 and above. Write code to test each grade range.
Write code that prints “Fizz” when the number is divisible by 3, “Buzz” when it is divisible by 5, and “FizzBuzz” when it is divisible by 3 and 5 (If a number is divisible by 3 and 5, it should also print “Fizz” and “Buzz”).