bembry.org
Home / Technology / Python / Exercises

Python Lesson 11 Exercises: Lists

In the following exercise, pay attention to your user interface, and be certain to test the programs rigorously. Save each program as pa11-1.py, pa11-2.py and so forth.

Exercise 1:
Edit the Pig Latin translator in exercise pa9-1 so that it can translate a whole sentence into Pig Latin instead of just a single word.

Exercise 2:

Create a program that will put words in alphabetical order. The program should allow the user to enter as many words as he wants to.

Exercise 3:

Create a password generating program. The program should randomly select numbers, letters, and symbols from a list to create a password of the length determined by the user.

Exercise 4:
Create a program that plays the classic card game "War", but which allows the player to choose which card to play. The game should start by randomly dealing a 26-card deck (two suits from a standard card deck) into two stacks of cards, one for the computer and one for the player. The player should be able to see all of his cards. The game should randomly decide who goes first, the computer or the player. Then, the first player will lay down a card and the second player must choose one card from his deck to play against the other card (the computer will lay down a card at random). The player with the higher card wins the hand, gets points, and gets to choose which card to start the next hand. When all cards have been used, the game is over and the player with the highest score wins.

Alternative 1:
Create a program that will play "Paper, Rock, Scissors" against the computer.

Alternative 2:
Create a program that will check a sentence to see if it is a palindrome. A palindrome is a sentence that reads the same backwards and forwards ("madam in eden i'm adam"). The program should ignore spaces and punctuation and look only at the order of the letters.

Lesson Exercises Python Lessons Homepage

Restricted access