Question: 6.25 Lab 3, Part 2: Rotate a letter for Caesar Write a rotate() function that takes two parameters, a string intended to be one upper-case

6.25 Lab 3, Part 2: Rotate a letter for Caesar

Write a rotate() function that takes two parameters, a string intended to be one upper-case A-Z letter and an integer, and returns a string. *The returned string should be the *input letter rotated by the number of positions specified by the integer argument*. (The Romans of Caesar's time only used what today we call upper-case letters.)

So a call to rotate("C", 1) should return (return not print) the string D and a call to rotate(D, -1) should return the string "C". Rotation should "wrap around" the end of the alphabet, so rotate("Z", 3) should return "C".

Hints:

  • It will be useful for you to use a string containing all the upper case letters in order. You probably want to use a variable assignment for this.
    • Then you can use the find() function discussed in Tuesday's lecture to find the index of a character in the alphabet (also described in Zybooks 7.1, which also has a lot of other stuff).
    • And indexing of strings
  • You will want to use the remainder function % together with addition (+) to the get the wrapping around the end of the alphabet behavior. -Remember: Our lab and project assignments never use the Python input() statement unless we explicitly say so, which from here on out we will almost never do.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!