CSC 171 - Introduction to Computer Programming

Lab Assignment #10 - Working with Strings In A Program

Due Monday, October 16, 2023

From our work with strings so far, we have seen that we can compare strings using the same relational operators as we have used before: >, ≥ , ==, !=, <, ≤

  1. We know from our earlier work that you can use the == operator to see if two strings are the same:

    An example of how this may be used:

    # s is a string
    # p and q are Boolean
    s = input("Enter some text")
    p = s ==  "The end"
    q = s == "the end"
    If the user typed in "The end" p is True and q is False (equals is case sensitive).

    Write a program that prompts the user for a line of text, prints it and repeats this until the user types "The end".

  2. Using the string methods that we have learned so far, write a program that will allow the user to type in line of text until the user types in the phrase "The end" on a line by itself.

    The program will print the number of lines that contain the string "is".

    Strings has a basic method that you will need for this assignment:

[Back to the Lab Assignment List]