Skip to content

Latest commit

 

History

History
80 lines (64 loc) · 3.79 KB

File metadata and controls

80 lines (64 loc) · 3.79 KB

The program does the following:

  1. Pick a language that is not English and look up how to say a few common phrases, such as "Hello", "Goodbye", etc
  2. Creates a dictionary with these common phrases from the languages selected as the key and their English translation as the values.
  3. Display a "Welcome" message to the user describing the programmer's purpose.
  4. Display a list of the phrases from the selected language to the user. Hints: Use the ".keys()" method of the dictionary class.
  5. Ask the user to type in a phrase to translate.
  6. Display to the user the phrase they selected and what its English translation is.
  7. The program should look like this:
image

Working with Strings

Basic String Operations

All standard sequence operations work with strings

  • Indexing
  • Slicing
  • Multiplication
  • Membership
  • Length
  • Minimum
  • Maximum

However...

  • Strings are immutable
  • All item or slice assignments are illegal
image You can not assign a value to a part of a string. You can "Reassign" a new string to a variable, however.

Conversion Specifiers

image %s parts are "conversion specifiers. Use format to display values. Conversion specifies where to insert values. "s" means values should be formatted as strings. If they aren't strings, Python uses the _str_ function to convert them to strings. To include a percent sign in a format string, use %%

Float Formatting Specifier

image 3 decimal positions of precision.

String Formatting Long Version

String Methods

  • Python.org documentation has a complete list of string methods
  • The following slides are a sample of methods available.

String Find Method

image If the string is not found, it returns -1

Providing Start and End index

image The first number is inclusive. Last is exclusive.

Other Methods

  • rfind
  • index
  • rindex
  • count
  • startswith
  • endswith

Join

image Can not join string to int. image

Lower

image

Replace

image

Split

image If no parameters are set default is any whitespace character(space, tab, etc). image Don't forget space!

Maketrans

image