EX05 - str Exercises


For lecture notes on strings, please review this page.

Exercise 00 – Abbreviate

This program will abbreviate a given string to only it’s uppercase letters.

  1. In the comp110/exercises directory create a new folder named ex05_strings
  2. Create a file named abbreviate.py in your comp110/exercises/ex05_strings folder.
  3. Define a function named abbreviate that is given a str value as a parameter and returns a new str abbreviation.
    1. The new str should contain only the uppercase letter of the input string.
    2. Only the relational operators < and > should be used for determining whether a letter is uppercase. No built-in string methods should be used.
  4. Define a main function that has no parameters and returns None.
    1. It should first use the input built-in function to prompt the user for text that has uppercase letters in it.
    2. It should then make use of your abbreviate function to convert the string to an abbreviation and print it out.
    3. Make sure to add a call to main at the bottom of your file.

Example program run:

Write some text with some uppercase letters: Happy BirthDay
The abbreviation is "HBD".
Write some text with some uppercase letters: American Standard Code for Information Interchange
The abbreviation is "ASCII".

Notes:

  • For full credit, your printed abbreviation should be surrounded with quotations.
  • Make sure to exactly match the output format shown in the example.

Exercise 01 - Likertmoji

This program will rate your feelings with an emoji.

  1. Create a file named likertmoji.py in your comp110/exercises/ex05_strings folder.
  2. At the top of your file create five global variables that will hold the code strings that represent the following emojis:
    • cowboy ~ "\U0001F920"
    • grinning face ~ "\U0001F603"
    • neutral face ~ "\U0001F610"
    • crying emoji ~ "\U0001F62D"
    • upside down emoji ~ "\U0001F643"
  3. Define a function named represent that is given a rating int as a parameter and returns the str representing the matching emoji given by the table below.

    Rating Emoji Code
    greater than 5 🤠 "\U0001F920"
    4 or 5 😃 "\U0001F603"
    3 😐 "\U0001F610"
    1 or 2 😭 "\U0001F62D"
    less than 1 🙃 "\U0001F643"
  4. Define a main function that has no parameters and returns None.
    1. It should first use the input built-in function to prompt the user for a rating from 1-5.
    2. It should then make use of your represent function to convert the rating to an code string for the appropriate emoji and print it out.
    3. Make sure to add a call to main at the bottom of your file.

Example program run A:

How do you feel on a scale of 1-5? 4
😃

Example program run B:

How do you feel on a scale of 1-5? -3
🙃

Formatting and Documentation

  1. You should have a module docstring with a complete first sentence describing your progam at the start of each exercise.
  2. In each of your files, initialize a global variable named __author__ set equal to your PID as a string
  3. You should provide a docstring inside each of your declared functions describing what the function does in each program.
  4. Above your call to main in each file add if __name__ == "__main__": . Be sure to indent your main() function call by one tab. This is important for allowing the grader to run. It should look like:

Submission

Go ahead and delete any submission zips lingering around in your workspace from the previous exercise.

When you are ready to submit for grading, close out any open Python Debug Console terminals using the Trash Can and then open up a clean, new terminal.

python -m tools.submission comp110/exercises/ex05_strings

This should produce a submission timestamped with the current date/time for uploading on Gradescope.

Make a Backup Commit

  1. Open the Source Control panel (Command Palette: “Show SCM” or click the icon with three circles and lines on the activity panel).
  2. Notice the files listed under Changes. These are files you’ve made modifications to since your last backup.
  3. Move your mouse’s cursor over the word Changes and notice the + symbol that appears. Click that plus symbol to add all changes to the next backup. You will now see the files listed under “Staged Changes”.
    • If you do not want to backup all changed files, you can select them individually. For this course you’re encouraged to back everything up.
  4. In the Message box, give a brief description of what you’ve changed and are backing up. This will help you find a specific backup (called a “commit”) if needed. In this case a message such as, “Finished Exercise 0!!” will suffice.
  5. Press the Check icon to make a Commit (a version) of your work.
  6. Finally, press the Ellipses icon (…) and select “Push” to send this backed up version to your workspace repository space on GitHub.