Saturday, January 17, 2015

Reversing a String

The simple program below demonstrates reversing a user inputted string.
Basic outline:
  1. User inputs a string
  2. An empty reverse string variable is created
  3. A while loop is utilized to create the reverse string by starting at the end of the user inputted string, using indexing.
  4. The reverse message is printed.

Tuesday, January 13, 2015

Word Jumble Game (Creating a new string from a given string)

The following program demonstrates the creation of a new string from a given string that is randomly selected from a Tuple. This program creates a "jumbled" version of the word and then asks the player to guess the word. See program below.

Using Tuples (slicing, concatenate)

The following program demonstrates the use of tuples. See the program below for slicing a tuple and concatenating a tuple.



Monday, January 12, 2015

Creating a New String With For Loop

The program below demonstrates the creation of a new string using a For Loop. The program below simply creates a new string from a user inputted string with the vowels removed. See below:


Thursday, January 1, 2015

Coin Flipping Counter

Here is a simple program where the computer flips a coin 100 times and outputs the number of Heads and Tails.

Here is the basic outline:
  1. Explain the program
  2. Set initial parameters
    1. # of heads
    2. # of tails
    3. # of flips
  3. Loop that flips coin 100 times and keeps tracks of Head or Tails
  4. Diplay total number of Heads and Tails
  5. User presses enter to exit program
 

Number Guessing Game


Using the not Logical Operator and Compound Conditions

In the program below, username is initialized as an empty string so it starts out as False, making not username True. The not username is True as long the string is empty. This forces the username to enter a username, or the loop will continue to ask for username until something is entered. Once an input is entered for username the not username is False and the loop stops, moving the program forward to password, which is set up in a similar manner. The table below summarizes the logic:

Username
not username
True
False
False
True

The program also demonstrates the use of and / or compound conditions. See examples below.


 

Pillow Image Library for Python

Pillow is a imaging library for Python. It adds support for opening, manipulating, and saving many different image file formats. The example below shows how to display image information and display the image. Pillow can also be used to crop images and apply many different imaging filters.


Sorting a Dictionary


Using the Zip Function on Lists

The zip function ties together lists to make tuples.