Are you fully caught up on while
, do while
and for
loops? Looking for more practice?
You can use the same code file that you used last class or make a new one - up to you.
-
printLine(char, width)
that prints a single line ofchar
's of lengthwidth
. You will use a for-loop to accomplish this. For Example:> printLine("H", 5) HHHHH > printLine("🤯", 10) 🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯 > printLine("👻", 3) 👻👻👻
-
printRect(char, height, width)
that prints a rectangle ofchar
's with the givenheight
andwidth
. You will use a for-loop to do this and you should use yourprintLine()
function from above to help. Example:> printRect("@", 4, 6) @@@@@@ @@@@@@ @@@@@@ @@@@@@
-
Read this one carefully, especially the return format. The Fibonacci Sequence is a series of numbers. The first two numbers are 0 and 1. The next numbers are found by adding up the two numbers before.
For example: 0, 1, 1, 2, 3, 5, 8, 13, 21. The next number in this series is 13+21 = 34.
Write the function
fib(n)
that returns a String containingn
values of the Fibonacci Sequence. Each value in the return String is separated by a comma and a space", "
For Example:fib(5)
returns the string"0, 1, 1, 2, 3"
meanwhilefib(11)
returns the string"0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55"
. Assume the parameter,n
, is an integer value >= 1. You will use a for-loop to accomplish this.
-
count(char, str)
Write the functioncount(char, str)
- given the stringstr
count how many timeschar
is found in the string and return that number.
For Example:> count("r", "Mr. Squirrel"); 3 > count(".", "Mr. Squirrel"); 1 > count("Z", "Mr. Squirrel"); -1
- If you never find the character, return -1.
squirrel_crypt(str)
Mr. Squirrel has developed an encryption algorithm that he's pretty sure nobody has every used before. It's so good that it can encrypt and decrypt a message when you use it.- Each letter is replaced with its reflective partner in the alphabet (A becomes Z, B becomes Y, M becomes N, O becomes L, S becomes H, etc). Huge hint - M and N are the middle of the alphabet.
- Each letter is changed from UPPERcase to lowercase and from lowercase to UPPERcase
- Spaces " " are replaced with commas "," and commas are replaced with spaces
- All other special characters are left alone
- The string is reversed (Hello <> olleH)
- The new string is returned!
Examples:squirrel_crypt("Here's a simple test."); // returns: .GHVG,VOKNRH,Z,H'VIVs squirrel_crypt(".GHVG,VOKNRH,Z,H'VIVs"); // returns: Here's a simple test. squirrel_crypt("The FBI agent's CSIS friend doesn't believe in UFO's!"); // returns: !H'luf,MR,VEVROVY,G'MHVLW,WMVRIU,hrhx,H'GMVTZ,ryu,VSg squirrel_crypt("!H'luf,MR,VEVROVY,G'MHVLW,WMVRIU,hrhx,H'GMVTZ,ryu,VSg"); // returns: The FBI agent's CSIS friend doesn't believe in UFO's!
🐿️