Category Archives: Assignments

Basic: Instructions 4 and Standard Deviation

Basic Instructions 4
Classwork:

This assignments can be done with the most basic set of instructions:

#######################################
#
#   G Elia
#   Program to calcualte the range of a
#   set of numbers
#   9/21
#   python 3.4
#
########################################

yesNo ="y"
smallest =int(input("Enter number: "))

while yesNo == "y":
    y=int(input("Enter another: "))
    if smallest > y:
        smallest = y
    yesNo = input("Would you like to continue? (y/n) ")
    
print("The smallest number is",smallest)

Make the change to the brain according to the different assignments.

If you are finished with the previous assignments, work on YI_BasicInstructions4.py to calculate the range of a set.

Homework: Write a program YI_StandarDeviation.py to calculate the standard deviation of a set of numbers.
The standard deviation for a set of 5 numbers is calculated with this formula:

Screen Shot 2013-09-17 at 9.13.22 AM

where N is the total number of values entered,in this case 5,  Screen Shot 2013-09-17 at 9.15.27 AM  is each value and  Screen Shot 2013-09-17 at 9.15.11 AM  is the mean of all the values.

Look into the Documentation page to find out how to find the square root.

screen-shot-2016-09-22-at-10-43-37-pm

NOTE: import math at the top of your program

Basic: BasicInstructions.py – BasicInstructions2/3.py and greetings.py

Click on the image to get to the download page
Screen Shot 2014-09-09 at 9.30.37 AM

Writing your first python programs

Basic Instructions 2:

Write a program, YI_BasicInstructions2.py with the following:

  1. Prompt the user for name and grade
  2. Reply with a message about the name and grade
  3. Assign the value of “54” to variable “x”
  4. Assign the value of “23” to variable “y”
  5. Display the result of multiplying the two variables with a message
  6. Prompt the user for two more numbers, find the sum of the two numbers and display the result in a message.
  7. Prompt the user for two more numbers, find the smallest and display it with a message.

Basic Instructions 3:
Write a program, YI_BasicInstructions3.py with the following:

  1. Asking for a number: input
  2. Storing a number
  3. Comparing a number
  4. Repeating the process: copy and paste?????
  5. Find the min
yesNo = "y"
while yesNo == "y":
    inputX = input("Enter an integer ")
            # 1. asking for a number: input and store the
            #  number in variable x
    x = int(inputX) # convert input to integer
    inputY = input("Enter another integer ")
            # 1. asking for another number: input and
            # store the number in variable y
    y = int(inputY) # convert input to integer
    if x > y:
         print (x, " is bigger than ", y)
    else:
         print (y, " is bigger than ", x)
    yesNo = input("Would you like to compare more numbers? y/n ")

print "Goodbye"

firstProgramFlowchart,,,,

Homework:
Write a python program, YI_greetings.py, to
1. prompt the user for name and grade
2. reply with, How are you feeling today, name?
3. reply with a comment about his or her grade using the name and he or she is feeling.

Topics covered so far


Review Part 1

Concepts we covered
if/else
Flowchart
nested if/else
range
for loop
definitions
lists
upper and lower

Basic Instructions, Control Statements and Definitions Review Documents

Programming Assignments you should know:
palindrome
compound interest
asterisk shapes
tally and tally2
times table
permutations and combinations
mail order
temperature conversions

Conditionals: The Richter_Scale_YI.py Flowchart

Write a new program, guess_num_YI.py based on guess.py but without the “break” instruction. This program plays the game of “guess the number” as follows: Your program chooses the number to be guessed by selecting an integer at random in the range 1 to 1000. The program then displays:

I have a number between 1 and 1000.
      Can you guess my number?
      Please type your first guess.

The player then types a first guess. The program responds with one of the following:

 1. Excellent! You guessed the number! You guessed in 4 tries.
       Would you like to play again (y/n)?
    2. Too low. Try again.
    3. Too high. Try again.

If the player’s is incorrect, your program should loop until the player finally gets the number right. Your program should keep telling the player Too high or Too low to help the player “zero in” on the correct answer. After a game ends, the program should report the number of games the player played and prompt the user to enter “y” to play again or “n” to exit the game.

Random numbers:

###################################################################
# Mrs. Elia
# 10/21
# python 3.7
# Description: How to generate pseudorandom numbers
#
###################################################################

import random

yesNo = input("would you like a random number?y/n ")

while yesNo == "y":
    print (random.randrange(1,7))
    yesNo = input("would you like a random number?y/n ")
print ("goodbye")

##>>>
##would you like a random number?y/n y
##5
##would you like a random number?y/n y
##4
##would you like a random number?y/n y
##3
##would you like a random number?y/n

 

For next assignment search in the internet for the Richter magnitude scale and write a program, RichterScale_YI.py that prompts for the number scale and prints the description of the earthquake intensity: micro, minor, light, moderate, strong, major and great. Use nested if/else statements.

The flowchart for the Richter_Scale_YI.py assignment – Use google docs: drawing or draw.io

flowchart-1

lowchartup

Basic: Concepts – CircleCalc_YI.py and isMultiple_YI.py

Programming Assignments for claswork/Homework:

  1. Write a program, CircleCalc_YI.py that reads in the radius of a circle and prints with an user friendly message the circle’s diameter, circumference and area.
    After your header:

    import math # on first line
    piVariable = math.pi

  2. circle

  3. Write a program, isMultiple_YI.py that reads in two integers and determines and prints with an user friendly message whether the first is a multiple of the second. ( Hint: Use the modulus operator. )

multiple

Basic: Concepts – Palindrome

Interesting resource:
Screen Shot 2014-09-25 at 8.49.06 AM

Palindromes

A 5-digit palindrome number is a number than if read from right to left is the same as if it is read from left to right.

Some examples are: 12321, 74947 and 21812.

Classwork: write a python program, Palindrome_YI.py to prompt the user for a 5-digit number and print if it is a palindrome or not.

Homework:
Write the program for this flowchart:
Screen Shot 2014-09-25 at 9.33.01 AM

Conditionals: Nested if/else structures

Test for multiple cases by placing if/else structures inside other if/else selection structures.
Here is a good example using pseudocode:
Print A for exam grades greater than or equal to 90, B for grades between 80 and 89, C for grades between 70 and 79, D for grades between 60 and 69 and F for all other grades.

if student's grade is greater than or equal to 90
        print "A"
   else
        if student's grade is greater than or equal to 80 
             print "B"
        else
             if student's grade is greater than or equal to 70
                  print "C"
             else
                  if student's grade is greater than or equal to 60
                       print "D"
                  else
                       print "F"

Here is a program snippet:

if grade >= 90:
   print ("A")
else:
   if grade >= 80:
      print ("B")
   else:
   ...

It can also be written in this format:

if grade >= 90:
   print ("A")
elif grade >= 80:
   print ("B")
elif ...

Question:

1. Would the program still work as intended if the symbol >= was changed to <= ???

2. Can I write this program as follows?

if grade >= 90:
   print "A"
if grade >= 80 and grade < 90:
   print "B"
if grade >= 70 and grade < 80:
   print "C"
if ...

3. Can you come up with a different way of writing the program and still in an efficient way?

Here is a flowchart for this structure:

gralNestedIfElseStruct

Here is the starting of the flowchart for the grade assignment:

partialNestedIfElse

Assignments:

  1. Finish the flowchart
  2. Write a program, letter_grade_YI.py. This python program prompts the user for a numeric grade and prints the letter grade.
  3. Write an efficient program, many_letter_grades_YI.py as you discovered in the previous post. This python program prompts the user for a numeric grade and prints the letter grade. Additionally, it continues to prompt the user until the user says ā€œnā€ to quit.
  4. BEFORE YOU START CODING, DRAW THE FLOWCHART, and don’t start coding until I check it.

Conditionals and loops: Rock, paper, scissors

2. Write a pyhton program, RoSciPa_YI.py that plays the rock-paper-scissors game against the computer. When played between two people, each person picks on e of three options (usually shown by a hand gesture) at the same time, and a winner is determined.

In the game, rock beats scissors, scissors beats paper, and paper beats rock. The program should randomly choose one of the three options (without revealing it), then ask for the user’s selection. At that point, the program reveals both choices and prints a statement indicating that the user won, that the computer won, or that it was a tie. Keep playing until the user chooses to stop, then print the number of user wins, losses, and ties.

rock-paper-scissors-freebie

Loops – ā€œwhileā€ and ā€œif/elseā€ structures

Visit the site below to learn about new topics:
ā€¢ import statements
ā€¢ Modules
ā€¢ The randint() function
ā€¢ for statements
ā€¢ Blocks
ā€¢ The str(), int(), and float() functions
ā€¢ Booleans
ā€¢ Comparison operators
ā€¢ Conditions
ā€¢ The difference between = and ==
ā€¢ if statements
ā€¢ break statements

screen-shot-2016-10-05-at-4-44-45-am

Open the post “Lesson Questions” to submit all the work we learn in class.
Write a new program, guess_num_YI.py based on guess.py but without the “break” instruction. This program plays the game of “guess the number” as follows: Your program chooses the number to be guessed by selecting an integer at random in the range 1 to 1000. The program then displays:

I have a number between 1 and 1000.
      Can you guess my number?
      Please type your first guess.

The player then types a first guess. The program responds with one of the following:

 1. Excellent! You guessed the number! You guessed in 4 tries.
       Would you like to play again (y/n)?
    2. Too low. Try again.
    3. Too high. Try again.

If the player’s is incorrect, your program should loop until the player finally gets the number right. Your program should keep telling the player Too high or Too low to help the player “zero in” on the correct answer. After a game ends, the program should report the number of games the player played and prompt the user to enter “y” to play again or “n” to exit the game.

Random numbers:

###################################################################
# Mrs. Elia
# 10/21
# python 3.7
# Description: How to generate pseudorandom numbers
#
###################################################################

import random

yesNo = input("would you like a random number?y/n ")

while yesNo == "y":
    print (random.randrange(1,7))
    yesNo = input("would you like a random number?y/n ")
print ("goodbye")

##>>>
##would you like a random number?y/n y
##5
##would you like a random number?y/n y
##4
##would you like a random number?y/n y
##3
##would you like a random number?y/n

 

For next assignment search in the internet for the Richter magnitude scale and write a program, Richter_Scale_YI.py that prompts for the number scale and prints the description of the earthquake intensity: micro, minor, light, moderate, strong, major and great. Use nested if/else statements.

Loops: Powers of Ten

Assignment:
Write a program, powers_of_ten_YI.py that prints the powers of ten using the “for” loop.

>>> 
What is the exponent for the powers of ten? 20
1.0
10.0
100.0
1000.0
10000.0
100000.0
1000000.0
10000000.0
100000000.0
1000000000.0
10000000000.0
100000000000.0
1000000000000.0
10000000000000.0
100000000000000.0
1000000000000000.0
1e+16
1e+17
1e+18
1e+19
>>> 


Loops: Nested Loops Challenge

Classwork:

Challenge Assignment:

##This program will display the products of two numbers from 1 to 10
##in the form of a two-dimensional table.
##   1 |    2 |    3 |    4 |    5 |    6 |    7 |    8 |    9 |   10 | 
##______ ______ ______ ______ ______ ______ ______ ______ ______ ______ 
##   1 |    2 |    3 |    4 |    5 |    6 |    7 |    8 |    9 |   10 | 
##   2 |    4 |    6 |    8 |   10 |   12 |   14 |   16 |   18 |   20 | 
##   3 |    6 |    9 |   12 |   15 |   18 |   21 |   24 |   27 |   30 | 
##   4 |    8 |   12 |   16 |   20 |   24 |   28 |   32 |   36 |   40 | 
##   5 |   10 |   15 |   20 |   25 |   30 |   35 |   40 |   45 |   50 | 
##   6 |   12 |   18 |   24 |   30 |   36 |   42 |   48 |   54 |   60 | 
##   7 |   14 |   21 |   28 |   35 |   42 |   49 |   56 |   63 |   70 | 
##   8 |   16 |   24 |   32 |   40 |   48 |   56 |   64 |   72 |   80 | 
##   9 |   18 |   27 |   36 |   45 |   54 |   63 |   72 |   81 |   90 | 
##  10 |   20 |   30 |   40 |   50 |   60 |   70 |   80 |   90 |  100 |

List: Basic Assignments


Write a python program, list_basic_assigments_YI.py
1. Create a_list and assign 20 random integer numbers between 50 and 75.
2. Create a new_list with 20 random integer numbers between 61 and 91.
3. Create another list, newer_list whose items are the sum of each item on the lists a_list and new_list
4. Create a histogram from a list of values.

# Creating a histogram from a list of values.

int_values = []   # a list of values

# input 8 integers from user
print ("Enter 8 integers between the values of 1 and 10:")

for i in range( len(int_values) ):
   new_value = int( input( "Enter integer %d: " % ( i + 1 ) ) )
   int_values += [ new_value ]

# create histogram
print ("\nCreating a histogram from int_values:")
print ("%s %10s %10s" % ( "Element", "Value", "Histogram" ))

for i in range( len( int_values ) ):
   print ("%7d %10d  %s" % ( i, int_values[ i ], "*" * int_values[ i ] ))


5. Create and display a histogram from a list of 10 random integer values between 5 and 9.
6. Use a list to solve the following problem: “Read in” 6 numbers. As each number is read, print it only if it is not a duplicate of a number already read.

Required Submission
1. Copy and paste the programs in the Text Entry tab.
2. Submit the list_basic_assigments_YI.py or the repl.it link.
NOTE: Documentation
Header:
a) Assignment description ( you can copy and paste the assignment itself)
b) Author’s name
c) Language and version
d) Date of completion
Input/Output:
Input(If any) and output for each part.

List: sum of all

Sum of all items in a list

More for loops

 

###################################
#
#  tally.py
#  
#  Mrs. Elia
#  12/12
#  for loops: find the sum of all the
#  numbers in the list
#
###################################


aSeq = [8,6,3,2,10]
tally = 0

for i in aSeq:
    tally += i
print ("The total of all the items in the list ", aSeq, "is ", tally)


##>>> 
##The total of all the items in the list  [8, 6, 3, 2, 10] is  29
##>>> 

Class work:

Write a python program, Tally1_YI.py to find the sum of the numbers from x to y where x and y are two numbers the user inputs. Your program should prompt the user for x and y. Make sure your program checks x is smaller than y.

Write a python program, Tally2_YI.py to find the sum and the average of the following list: [45,23,76,18,90,123,56,76,89,22,41,56]
The output should look like this:
The sum of all the items in this list [45,23,76,18,90,123,56,76,89,22,41,56] is xxx and the average is xxx.xx.

 

List: list to calculate salaries

Programming Project: Using a list to calculate salaries

Use a list to solve the following problem: A company pays its salespeople on a commission basis. The salespeople receive $200 per week, plus 9% of their gross sales for that week. For example, a salesperson who grosses $5000 in sales a week receives $200 plus 9% of $5000, or a total of $650. Write a program (using a list of counters) that determines how many of the salespeople earned salaries in each of the following ranges (assume that each salespersonā€™s salary is truncated to an integer amount):
a. $200-299
b. $300-399
c. $400-499
d. $500-599
e. $600-699
f. $700-799
g. $800-899
h. $900-999
i. $1000 and over
NOTE: DO NOT USE “if” STATEMENTS.

Input Data: (must use this data)
gross_sales_list = [5390, 4850, 5762, 333, 4104, 720, 2854, 5730, 7918, 6582, 7874, 8703, 4006, 2027, 9410, 6294, 6083, 1494, 7337, 8682, 340, 4390, 8900, 3620, 776, 7049, 238, 7415, 9946, 4154, 2109, 6935, 2421, 7448, 9452, 3494, 91, 3702, 9641, 3630, 7291, 8624, 692, 2256, 8121, 6127, 4849, 7830, 570, 8699, 5365, 6325, 8620, 2079, 3331, 2962, 9853, 7798, 4051, 413, 1571, 267, 1954, 5118, 3639, 3215, 2705, 3600, 8949, 3337, 583, 8117, 1867, 810, 8477, 3298, 8705, 9704, 3446, 4812, 2182, 6387, 9933, 8049, 587, 7256, 7898, 4939, 4715, 4323, 2583, 4188, 4567, 6409, 9110, 458, 3187, 9742, 6964, 8245]

Output:
Display the categories as above followed by the frequency for each of them. For example:
$200 – $299 14 **************
$300 – $399 8 *********
$400 – $499 10 **********
$500 – $599 15 ***************
ā€¦
Include in your output
– Any error messages that show why your program doesnā€™t work.
– An explanation related to the program failure if that is the case.

List: Pig Latin Project

NOTE: USE SLICING FOR THESE ASSIGNMENTS

Programming Project:
One of the rules for converting English to Pig Latin states: If a word begins with a consonant, move the consonant to the end of the word and add ā€œayā€. Thus ā€œdogā€ becomes ā€œogdayā€, and ā€œcrispā€ becomes ā€œrispcayā€. If the word starts with a vowel, move the vowel to the end of the word and add the vowel followed by “way”. Example: “about” would turn into “boutaway” There are some variations to this last rule but it is ok if you do something else.

Write 2 python programs to convert from English to Pig Latin.
1. The first program, PigLatinWord_YI.py, should prompt the user for one English word. Your program then should display the word in Pig Latin.
2. The second program, PigLatinPhrase_YI.py, should prompt the user for a full sentence in English. Your program then should display the sentence in Pig Latin.

Recall what we learned from hangman.py
https://inventwithpython.com/chapter9.html

def displayBoard(HANGMANPICS, missedLetters, correctLetters, secretWord):
    print(HANGMANPICS[len(missedLetters)])
    print()
 
    print('Missed letters:', end=' ')
    for letter in missedLetters:
        print(letter, end=' ')
    print()
 
    blanks = '_' * len(secretWord)
 
    for i in range(len(secretWord)): # replace blanks with correctly guessed letters
        if secretWord[i] in correctLetters:
            blanks = blanks[:i] + secretWord[i] + blanks[i+1:]
 
    for letter in blanks: # show the secret word with spaces in between each letter
        print(letter, end=' ')
    print()
 

List: SwapOandE_YI.py and slicing

Classwork:

What does each of the following statements print?
Answer this question and explain what each of them does on edmodo.com ( Use IDLE )
NOTE: be clear
words = “happy face”
print(words[1:3])
print(words[2:-1])
print(words[:])
print(words[:5])
print(words[5:])
print(words[::3])

Write a short python program, SwapOandE_YI.py to replace an ‘o’ with an ‘e’. Prompt the user for a word and display the swapped version of it if it contains an o. Otherwise, the program will just display the original word. This program must use the slicing technique you learned in the Hagman program.
Example:

Type a word and I will replace any 'o' with an 'e': broom
The swapped word is: breem
>>> 

Algorithm: Tic-Tac-Toe Functions

February 9th, 2016

Tic Tac Toe program is due on 2/11/16.

Keep in mind programming style tips we have been discussion since the beginning of the year:
1. Documentation: COMMENTS – the header and a short line in each function definition.
2. Naming: use relevant names for variables and functions.
3. Test all possible scenarios to make sure every part of the program executes successfully.

Screen Shot 2016-02-11 at 8.13.56 AM

NOTE: TO MAKE IT MORE INTERESTING AND INVITING TO THE PLAYER, MAKE THE FIRST COMPUTER MOVE RANDOM. However, it should be intelligent once the game is on.

A- 1 day late
B+ 2 days late
B 3 days late
B- 4 days late
C+ 5 days late
C 6 days late
C- 7 days late
D+ 8 days late
D 9 days late
D- 10 days late
F 11 days late
0 after 11 days pass the due date

I encourage you to talk to me ahead of time if this is a problem.

These two functions can be borrowed from the author’s program:


def drawBoard(board):
    # This function prints out the board that it was passed.

    # "board" is a list of 10 strings representing the board (ignore index 0)
    print('   |   |')
    print(' ' + board[7] + ' | ' + board[8] + ' | ' + board[9])
    print('   |   |')
    print('-----------')
    print('   |   |')
    print(' ' + board[4] + ' | ' + board[5] + ' | ' + board[6])
    print('   |   |')
    print('-----------')
    print('   |   |')
    print(' ' + board[1] + ' | ' + board[2] + ' | ' + board[3])
    print('   |   |')

and

def isWinner(bo, le):
    # Given a board and a player's letter, this function returns True if that player has won.
    # We use bo instead of board and le instead of letter so we don't have to type as much.
    return ((bo[7] == le and bo[8] == le and bo[9] == le) or # across the top
    (bo[4] == le and bo[5] == le and bo[6] == le) or # across the middle
    (bo[1] == le and bo[2] == le and bo[3] == le) or # across the bottom
    (bo[7] == le and bo[4] == le and bo[1] == le) or # down the left side
    (bo[8] == le and bo[5] == le and bo[2] == le) or # down the middle
    (bo[9] == le and bo[6] == le and bo[3] == le) or # down the right side
    (bo[7] == le and bo[5] == le and bo[3] == le) or # diagonal
    (bo[9] == le and bo[5] == le and bo[1] == le)) # diagonal

List: memory cards

Classwork: Homework discussion
The assignment below is designed to help you implement the memory cards program.
The idea is that letters a through h are associated with rectangles rect_a through rect_h. When a player chooses letter a, he or she is choosing rect_a. Think of this: when the user click on a memory card all you know is the location of the point and then you use the point to figure out which rectangle contains that point.
A rectangle in this assignment is associated with a file name just like in the memory cards a rectangle is associated with an image ( an image name ).
If you look at rect_a and rect_e, both are associated with the same file name. So picking a rectangle allows you to check whether the names are equal. But how do you work this out when you shuffle them? That is the part you have to think about.

rect_a = 'a'
rect_b = 'b'
rect_c = 'c'
rect_d = 'd'
rect_e = 'e'
rect_f = 'f'
rect_g = 'g'
rect_h = 'h'

original_images = ['trees.bmp','sky.bmp','water.bmp','lilypads.bmp','trees.bmp','sky.bmp','water.bmp','lilypads.bmp']
    
rectangles = [rect_a,rect_b,rect_c,rect_d,rect_e,rect_f,rect_g,rect_h]


## Write a program in python, twoMatchingFiles_YI.py to prompt the user for two strings from 'a' through 'h'(in the alphabet). Use the variables shown above.
## 1. Check if the user guesses two matching bmp file names. Use a for loop to accomplished this.
## 2. Loop until the user found a match.
## 3. Prompt the user to quit? or play again?
## 4. If play again is selected, randomly scramble the bmp file names before the program continues.
## 5. If you have already written your program for the matching cards, copy your code snippet
##    for this part of the program. 

Algorithm: Wheel of Fortune – Description and Design

1. Have the variable secretWord changed to secretPhrase and have a value assigned to it.
2. Prompt the user for a letter and display it in the right positions if it is in the secretPhrase. Otherwise, send a message to the player “incorrect” and keep track of how many times the player guesses the wrong letters.
3. Terminate the game after 5 tries. Display “game over” if it fails. Otherwise, displays “You are a winner!!” and add message with the prize(s)

Write YI_WheelOfFortune.py using what you learned from Hangman.py

1. Have the variable secretWord changed to secretPhrase and have a value assigned to it.
2. Prompt the user for a letter and display it in the right positions if it is in the secretPhrase. Otherwise, send a message to the player “incorrect” and keep track of how many times the player guesses the wrong letters.
3. Terminate the game after 5 tries. Display “game over” if it fails. Otherwise, displays “You are a winner!!” and add message with the prize(s)

Screen Shot 2014-11-16 at 5.52.28 PMScreen Shot 2014-11-16 at 5.53.09 PM

 

Designing the game:

  • Start by thinking to implement the secret phrase .
  • Make it similar to the secret word from the hangman.py program
  • The secret phrase has a phrase instead of a word. You have to think how you are going to handle the spaces. A suggestion from a student, Anna Schmult: replace a space with a “dash”. Shihan YU has a few good ideas about it. You can ask him also how he is handling this component.
  • Have a definition to randomly select a phrase
  • The definition should look very similar to getRandomWord(wordList) from hangaman.py
  • Write a short program to test your definition, and you handle the spaces and how you select randomly the phrase. Name this program YI_WheelOfFortune1.py
  • Next, work on the displayBoard() definition.
  • Don’t worry about the HANGMANPICS. You do not need it.
  • You can use the code for the missedLetters and the slicing to determine where the correct letter goes
  • Test your code works by writing a program YI_WheelOfFortune2.py. You can supply the list of phrases in the definition itself.
  • If you feel ambitious, you can add the code to the YI_WheelOfFortune1.py and return the secretPhrase as an argument to the displayBoard() definition.

 
 
THIS IS A GREAT PROJECT TO DISCUSS WITH YOUR CLASSMATES AND FROM OTHER PYTHON CLASSES!!! “DISCUSS” DOESN’T MEAN COPY THE CODE LINE BY LINE. IT MEANS UNDERSTAND THE STRATEGY AND APPLY IT TO YOUR OWN PROGRAM.

Algorithm: The Wheel of Fortune hangman n the game


Programming Project: The Wheel of Fortune
Write YI_WheelOfFortune.py using what you learned from hangman.py

Due date: November 25th, 2015

Screen Shot 2015-11-20 at 7.46.00 AM —> Screen Shot 2014-11-16 at 5.52.28 PMScreen Shot 2014-11-16 at 5.53.09 PM

For the last few days We have worked on understanding and assimilating Al Sweigart’s hangman.py program by taking the program apart and tracing it with different data to make sure we tested every line of code.

Now we can use the skills we learned to write a similar program to simulate the Wheel of Fortune. You can use the displayboard and getguess functions. You can collaborate with a partner but you should have your own program. No two programs should be alike!

The original game is multiplayer but you will implement it for only one player. Even though the behavior of the game should be reflected in your simulation, there are changes that have to be made to turn it into one player and still be a fun game. You might want to apply a penalty when the “lose a turn” comes up. This implementation of the Wheel of Fortune should handle only a word.

Somethings to keep in mind
Components that can help you through the process:

  1. A list of items on the wheel
  2. Random number for the spin simulation
  3. The “secret word”
  4. The “missed letters”
  5. The “correct letter”
  6. A “place holder” for the prizes

THE GAME

  1. Spin of the wheel: { gain or loss }
  2. If there is a gain, the player can guess a letter: { correct -> keeps the prize, incorrect -> loses the prize }
  3. The player can solve the puzzle before all the letters have been guessed.
  4. The player can buy a vowel if there is money in the “place holder”.
  5. The player gets to keep the prizes if the puzzle is solved.

NOTE: the program should allow the user to play the game after the puzzle was solved.

Dictionaries: Students Grades

Classwork:
Write a python program, StudentGrades_YI.py. The program has three dictionaries:
test1 = {‘bob’:88, ‘lisa’:100,…}
test2 = {‘bob’:85, ‘lisa’:95,…}
test3 = {‘bob’:80, ‘lisa’:98,…}

1. Add 5 more students (using the update method) and their grades in the dictionaries.
2. Create a dictionary with the students’ averages from test 1, 2 and 3.
3. Find the student with the highest average.
4. Print all the students names and averages.

pygame: BouncingOffWall.py

Another good link for drawing shapes.

Classwork:
Write a program, YI_BouncingOffWall.py similar to animation.py but with a short wall in the center of the window.
Challenge: Two walls in the center where the blocks will go through it. (Optional)

Screen Shot 2014-03-07 at 11.09.04 AM
Home work: Keep on reading chapter 17.
Screen Shot 2014-03-07 at 9.30.28 AM
Think about your next program. It will be related to the animation.py but with a simple maze.
Screen Shot 2014-03-07 at 9.29.25 AM

pygame: MazeBouncing_YI.py

Screen Shot 2014-03-10 at 4.30.38 PM

Classwork:
Write a pygame program, MazeBouncing_YI.py. Use the code you learned in animation.py but with a simple maze like the one below.
Screen Shot 2014-03-07 at 9.29.25 AM

Homework:
Visit edmodo.com to answer these questions from Chapter 17.

1. Coming soon.
2. What is 0.2 in the line: time.sleep(0.2)? How is it calculated?
3. What would happen if time.sleep(0.2) was omitted?
4. What would happen if windowSurface.fill(BLACK) was omitted and time.sleep(0.2) is changed to time.sleep(1.0)?

pygame: SpritesAndSound_YI.py

Classwork:
More on spritesAndSound.py

Write a python/pygame program, memoryCards2_YI.py similar to previous program, flashCards1_YI.py. However, in this program the user doesn’t know where the matching card is since the cards are not showing their images. If the user guesses right, the sound should indicate so and the two cards go away. Just like in the previous assignment the sound indicate when it is wrong. The card should be expose so the user will remember where the cards are.

memoryFlashCards

Homework: Start reading chapter 14 – Caesar Cipher

Screen Shot 2014-05-13 at 8.12.31 AM