CSC111 Nested-Loop Exercises
--D. Thiebaut 08:26, 29 September 2011 (EDT)
Single Loop
- What is the behavior of this loop?
cards = [ "As", "King", "Queen", "Jack" ] for card in cards: print( "Card = ", card ) cards.append( card )
Nested-Loops
- Create nested loops that will print the following patterns, without using the '*' * n construct.
***** ***** ***** *****
- triangle
* ** *** **** *****
- another triangle
***** **** *** ** *
- A rectangle of numbers
0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5
- Another square of numbers
0 1 2 3 4 5 1 2 3 4 5 6 2 3 4 5 6 7
- All the characters in the alphabet:
a b c d . . . y z
- Some of the account numbers for the class:
111a-aa 111a-ab 111a-ac ... 111a-az
- All the account numbers for the class
111a-aa 111a-ab 111a-ac ... 111a-az 111a-ba 111a-bb 111a-bc ... 111a-bz
- All the account numbers for the CS Department, with classes 111, 231, 270, and 240.