Exercise 4.7#
Try to complete this exercise using only the material that was presented before it.
Question 1#
Take a user input number (by using the input()
function) and print out the value squared. Make sure to use appropriate messages for the input and the print out.
Question 2#
Use a string slice to print out a user input backwards. Use an appropriate message for the input.
Question 3#
A spoonerism is a play on words where you take a phrase (normally one consisting of two words) and you swap the first letters of two of the words. For example “marco polo” becomes “parco molo”. Write a program which takes the two words as separate inputs (use appropriate messages for each, such as “Word 1: “ and “Word 2: “) and spoonerises them by printing them in one line with the first letters swapped. Use lower case for simplicity.
Test your code with the following examples:
“lighting a”, “fire”
“bad”, “money”
“jelly”, “beans”
“pack of”, “lies”
Question 4#
Create a script similar to Question 3, except swapping the first 2 letters of each word. Now “marco polo” becomes “porco malo”.
Test your code with the following example:
“crushing”, “blow”