Activecode Exercises

Answer the following Activecode questions to assess what you have learned in this chapter.

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.

Below is one way to write the program using the word ‘irritating’ as the string.

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.

Below is one way to write the program.

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”.

Below is one way to write the function longerString.

Let’s write the code for the cipherText function. cipherText should be a void function that takes the string input as a parameter, increases the value of each character by 1 (i.e. “bad” turns into “cbe”), and prints the encrypted string.

Below is one way to write the function cipherText.

Write a program that prints out the number of occurences of the character ‘t’ in the string tongue_twister, with declaration in the order of tongue_twister, count, and i. Declare the string tongue_twister as ‘twelve twins twirled twelve twigs.’

Below is one way to write the program.

Write a program that prints out the index of the second instance of the character ‘i’. Use string quote = "Your time is limited, so don't waste it living someone else's life.

Below is one way to write the program.

Deep in the forest live the 7 dwarves named Sorty, Torty, Vorty, Worty, Xorty, Yorty, and Zorty. Write a program that prints out each of their names.

Below is one way to write the program.

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”.

Below is one way to write the censorE function.

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”.

Below is one way to write the censorLetter function.

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.

Below is one way to write the alphaCombine function.

Let’s write a function called ispalindrome which takes a string named input and returns a bool The function returns true if the string 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”.

Below is one way to write the ispalindrome function.

You have attempted of activities on this page