To Course Home Page
IT 211 -- Examples
Index of Examples
Terminal I/O
- Hello Example -- Print a "Hello, World" message to the console.
- Greeter1 Example -- Input a name, then print a greeting to that person.
- Greeter2 Example -- Input name, color, background color, font family, and font size.
Output an HTML page containing a greeting.
- FrenchFlag Example -- Output ppm image of the French national flag.
Computations
Classification
Random Output
-
CoinFlip Example -- Show random output for simulated coin flip.
-
Magic8Ball Example -- Show a random response from a
Magic Eight Ball fortune telling ball.
-
ConsBSGen Example -- Construct random consultant sentence containing of a random verb, adjective, and noun.
-
Craps Example -- Play a simulated game of Craps.
Rules of Craps for one turn: roll the pair of dice:
- If the sum of the dice is 7 or 11, you win;
- else if the sum of the dice is 2, 3, or 12, you lose;
- else the sum establishes the point. Continue to
roll the dice until you the sum is 7 or the sum is equal to the point again. If
the sum was a 7, you lose; else if the sum was the point, you win.
Repeat this turn as many times as you wish. If you lose the turn, you lose
your bet. If you win the turn, you win the amount of your bet.
Indefinite Loops
-
CountTo100 Example -- Count to 100 (1, 2, 3, ..., 99, 100).
-
CountDownBy7s Example -- Count from 1000 to 1 backwards by sevens.
-
LongSong Example -- Display all verses of the song "99 Bottles of Beer on the Wall".
-
HailStone Example -- Print the HailStone sequence corresponding to a positive integer input.
-
Trace3 Example -- Construct variable trace and predict output.
-
Trace4 Example -- Construct variable trace and predict output.
-
DeafGrandma Example --
Unless you shout (all uppercase letters) grandma can't hear you. If you say BYE Grandma pretends not to hear you because she
doesn't want you to leave. You must repeat BYE three times before you can leave.
Comparison and Logical Operators
Double For Loops
User Defined Standalone Methods
-
StateRiddles Example -- Use methods to display riddles about various states.
-
ToFahr Example -- Use a method to convert a Celsius temperature to Fahrenheit.
-
OldMcDonald Example -- Use methods to display the song OldMacDonald Had a Farm. An example of code reuse.
-
MySqrt Example -- Compute the square root of a float with a user-defined method.
You don't have to understand how the method works to use it. You only need to know the inputs the the expected output of the method.
This is an example of encapsulation.
CreateFolders1 CreateFolders2 RenameFiles CreateBackups SequentialFileNames
Folders and Files
JavaScript Object Notation (JSON)
User Defined Classes
Answers to Review Exercise 1 and to Review Exercise 2 on May 23:
identified items in classes,
variable trace and output for test2.py files.