Chapter 13 Exercises¶
Fix 7 problems in the code below so that it runs.
Fix the errors in the code so that it prints “Less than 5” when a number is less than 5 and “Greater than or equal to 5” when it is greater than or equal to 5.
Fix 6 errors in the code below so that it works correctly.
Complete the code to get user input, and make choices based off the input. The input should either be “in”, “left”, or “right”; make sure the user knows that.
Fix the code below to assign grades correctly using elif and else. You can assume the numbers are all correct.
The following code prints both statements, change it so that it only prints the first one when the age is less than 6.
Change the code below to use elif and else rather than several ifs. Also fix it to print “Good job!” if the score is greater than 10 and less than or equal to 20 and “Amazing” if the score is over 20.
Complete the code so that it iterates through the list of numbers and prints positive, negative, or neither based off the integer.
Change the code below to use
elif
andelse
.Fix the errors in the code and change it to use elif’s and else so that if the user’s score is greater than the high score, it prints “Good job!”, if it’s lower, print “Try again.”, and if it’s the same print “You tied the high score”.
Change the following code to use
elif
andelse
instead.Add statements to the code, so that if the user gives a number less than 5, you ask for the input again, and have another set of decision statements based off if the number is greater than, less than, or equal to 3.
Change the code below to use only 1
if
, 1elif
, and 1else
.Fix the code and change the statements so there are three sets of if and else and 2 elifs.
Change the code below into a procedure that takes a number as a parameter and prints the quartile. Be sure to test each quartile.
Fix the code so that it prints only 1 thing for each age group and uses elif and else.
Write a function that will take a number as input and return a fortune as a string. Ask the user to pick a number to get the fortune before you call the function. Have at least 5 different fortunes. Use
if
,elif
, andelse
.Write a function that takes in a list of grades and returns the letter grade of the average (A is 90+, B is 80-89, C is 70-79, D is 60-69, F is 59 and below). Call the function and print the result.
Write a procedure to tell an interactive story and let the user choose one of at least 3 options.
Write code that iterates through number 1 - 20 and prints “Fizz” if it’s a multiple of 3, “Buzz” if it’s a multiple of 5, “FizzBuzz” if it’s a multiple of 3 and 5, and the number if it’s not a multiple of 3 or 5. It should only print one statement per number.