Python 2.2

String Methods

  • Fully automatically graded on code quality, style, structure and functionality
  • Students write their solution in an online IDE in their LMS
  • Check for Python code plagiarism

Pre-requisites:

  • Print statements.

Learning goals:

  • Learn how to interact with strings.
Get access to an autograder, plagiarism checker and online IDE for this assignment now!

Task:

The string data type (literally meaning a string of characters) is very commonly used in your Python scripts that use  I/O (input and output). Any input you get via the `input()` function is initially saved and handled as a string. Luckily, Python has many built in methods specifically for string objects, which you can use to validate input or process any string.

In this assignment, you will use Python’s built-in string methods to interact with the string:

`sentence = “Python is my favorite programming language!”`

Write a program called `string_methods.py`, in which you define the string above. After defining it, you will use string methods to perform the next tasks:

  1. Print the full string as it is.
  2. Print a version of the string with only uppercase letters.
  3. Print the number of times the letter ‘o’ is present in the string.
  4. Print a version of the string in which “my” is replaced with “everyone’s”.
  5. Print True if all characters in the string are alphabetical, print False if not.
  6. Print True if all characters are ASCII characters, print False if not.
  7. Print True if all characters in the string are digits, print False if not.

Please note that all of the above is hardcoded and will result in the same output every time.

Example usage:

-!- CODE language-bash -!-$ python3 list_methods.py
Python is my favorite programming language!
PYTHON IS MY FAVORITE PROGRAMMING LANGUAGE!
3
...

Learn more:

Start teaching Python now

CodeGrade is your virtual teaching assistant for your coding classroom. You teach, CodeGrade takes care of the rest.

With our 40+ built-in fully automatically graded Introduction to Python assignments for university-level courses, you can start teaching Python at your institution with confidence now. Or, scale your classroom with CodeGrade's tools.

Book a personal 30-minute demo now and we'll show you how to get started with CodeGrade in less than 1 hour!

Book a demo now!

Happy educators

  • Educators who use CodeGrade have less stress.
  • Educators who use CodeGrade have happier and more successful students.
  • Educators who use CodeGrade have a simpler teaching workflow.

Schedule a personalized tour of CodeGrade today.