Mixed-Up Code Exercises¶
Answer the following Mixed-Up Code questions to assess what you have learned in this chapter.
Construct a block of code that prints the remainder of 18 when divided by 13.
Construct a function that prints whether a number is true.
Construct a function that prints the difference of a and b if the result would result in a positive number. Otherwise, prints -1.
Construct a function,
matic, that takes as inputs 2 integers, x and y, and prints “automatic” if x is
an odd number, “systematic” if x is greater than y, AND
“hydromatic” if y is not equal to x. Check all 3 conditions.
Construct a block of code that prints “Pick me!” if x is equal to y, “Choose me!” if x is less than y, OR “Love me!” if x + y is even.
Construct a function that prints your letter grade according to this scheme. [0, 70) = F, [70, 80) = C, [80, 90) = B, and [90, 100] = A.
According to a logic game, a knight is someone who cannot tell a lie, and a knave is someone who cannot tell the truth. Construct a function that takes two booleans: the truth value of the story, and the truth value told by the person. The function should print whether the person was a knight or a knave.
If a cat is in a good mood, it purrs; when it’s in a bad mood, it meows. If a doog is in a good mood, it barks; when it’s in a bad mood it woofs. Construct a function that accomplishes this.
Construct a recursive function that tells the user to enter a positive number. It should then output that number to the terminal. If the user enters a negative number or zero, prompt the user again.
In the table of ASCII characters, the lowercase alphabet consists of characters 97-122. The uppercase alphabet consists of characters 65-90, which is a 32 character shift back from the lowercase. Construct a recursive function that asks the user to input a LOWERCASE character, converts that character to UPPERCASE character and prints it. If the user enters a character outside of the range of the LOWERCASE alphabet, prompt the user again. Hint: “||” means “or” when used between two conditional statements.