7.18. Mixed Up Code Practice¶
Write a program that prints the 4th character of word, and finds and replaces all instances of ‘i’ with ‘e’. Finally, print out the string. Put the necessary blocks in the correct order.
An anagram is a play on words by rearranging the letters of the original words to form new words. For example, the letters in “listen” can be rearranged to make “silent”. Write a program that rearranges “night” into “thing” and prints the anagram. Put the necessary blocks in the correct order.
Let’s write the function longerString, which takes two parameters, first and second. If first has more letters than second, longerString prints “first is longer than second”, and vice versa. If they have the same number of letters, longerString prints “first and second are the same length”. Put the necessary blocks in the correct order.
Let’s write the code for the cipherText function. cipherText should be a void function that takes input as a parameter, increases the value of each character by 1 (i.e. “bad” turns into “cbe”), and prints the encrypted string.
The program below should print out the number of occurences of the character ‘t’ in the string tongue_twister but the code is mixed up. Put the necessary blocks in the correct order, with declaration in the order of tongue_twister, count, and i.
The program below should print out the index of the second instance of the character ‘i’ but the code is mixed up and contains extra blocks. Put the necessary blocks in the correct order.
Deep in the forest live the 7 dwarves named Sorty, Torty, Vorty, Worty, Xorty, Yorty, and Zorty. The program below should print out each of their names but the code is mixed up and contains extra blocks. Put the necessary blocks in the correct order.
On the strange planet of Noes, there’s a law that prohibits the usage of the letter “e”. As a result, they hired you to write a function called censorE that replaces all occurences of the letter “e” in a string with an asterisk and returns the censored string. For example, if the input is “hello world”, the function returns “h*llo world”.
Your work for the planet of Noes impressed the nearby planets of Noas, Nois, Noos, and Nous. They want you to write different functions that censor out each planet’s corresponding forbidden letter. However, your galaxy brain knows better than to write a different function for each planet. Using generalization, write the function censorLetter which takes input and a char to censor as parameters and returns a censored string. For example, censorLetter(“Bye world”, ‘o’) returns the string “Bye w*rld”.
Let’s write a function called alphaCombine which takes two strings, first and second, and returns a string which concatenates first and second in alphabetical order. For example, alphabetizer (“zebra, mega”) returns the string “megazebra” since “mega” comes before “zebra” in the alphabet. Put the necessary blocks in the correct order.
Let’s write a function called <code>ispalindrome</code> which takes a <code>string</code> named input and returns a <code>bool</code> The function returns true if the <code>string</code> is a palindrome and false if not. palindromes are symmetrical strings. That is a string that reads the same backwards is palindrome. palindromes: “hih”, “i”, “bob”, “tenet”, “soos”, “madam” . not palindromes: “join”, “hat”, “frat”, “supper”, “rhythm”. The code is mixed up and contains extra blocks. Put the necessary blocks in the correct order.