Author Archives: graceliana@gmail.com

pygame: space invaders

Collision detection and input

Simplified Space Invaders
https://www.mysteinbach.ca/game-zone/1755/alien-invaders/

You can simplify the invaders to have different shapes.
You can simplify the shape of the buildings.
The behavior of the game has to be the same:
a. The invaders move right to left as they move down.
b. The bullets destroy the invaders ( they disappear).
c. The bullets destroy the buildings ( they disappear).
d. Keep score and lives.
e. Final message: Game Over

Optional Challenge: Have different levels of difficulty

Simplified Space Invaders
space invaders

pygame: Snake1_YI.py

Use the skills you learned in this class to write a program, Snake1_YI.py to play “snake” game.

Choose your favorite interpretation of this game.
Here is a link to the online version of snake.

Cryptography: myEncryption1_YI.py

Classwork:
ASCII table

Encryption Assignment 1:
A company has asked you to write a program, YI_myEncryption1.py to encrypt its data. Your program should read the entire string.

Start by converting every character to uppercase. Then find the ASCII code for the first character of the string and subtract 64 (for discussion’s sake, call this X). X is the key for the encryption. Go through the entire string: for each character use the key, X. You should return a string of integers (twice the length of the original string + 2, the ASCII value of the first character) but instead of letters, it is a list of encrypted ASCII codes.
NOTES:
1. Place the ASCII value of the first character in front of the string of numbers.
2. Keep the shift within the ASCII values of A through Z.

Example:
Horse
the code is: 728087906577

Homework: Write a program, YI_myDecryption1.py to decrypt a string of encrypted ASCII codes, first find the first two integers (if the EAC is 728077848487, the first two integers are 72. 72 is the first character of the string). This means that the first string’s encrypted ASCII code is 80. Change from 80 to its real ASCII value (figure out this algorithm on your own) and then subtract each two integers from the first real ASCII value.

Cryptography

Classwork:
ASCII table
Encryption Assignment 2:

Enforcing Privacy with Cryptography: The explosive growth of Internet communications and data storage on Internet-connected computers has greatly increased privacy concerns. The field of cryptography is concerned with coding data to make it difficult (and hopefully—with the most advanced schemes—impossible) for unauthorized users to read. In this exercise you’ll investigate a simple scheme for encrypting and decrypting data. A company that wants to send data over the Internet has asked you to write a program, myEncryption2_YI.py that will encrypt it so that it may be transmitted more securely. All the data is transmitted as four-digit integers. Your application should read a four-digit integer entered by the user and encrypt it as follows: Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing the new value by 10. Then swap the first digit with the third, and swap the second digit with the fourth. Then print the encrypted integer.

Write a separate application, myDecryption2_YI.py that inputs an encrypted four-digit integer and decrypts it (by reversing the encryption scheme) to form the original number.

Cryptography

Classwork:
Screen Shot 2015-05-14 at 9.26.24 PM
Caesar Cipher
Create a new file in Idle with the following program: cipher.py

Cryptography

The science of writing secret codes is called cryptography.
220px-Lorenz-SZ42-2
German Lorenz cipher machine, used in World War II to encrypt very-high-level general staff messages

In cryptography, we call the message that we want to be secret the plaintext. The plaintext could look like this:

Hello there! The keys to the house are hidden under the flower pot.

How would encrypt it so it would become a secret message?


You can use Idle to answer some of the questions.

1. What is the ASCII table? What is the range of numbers that is used in the table?
2. What is the first number where the alphabet starts? Is it lower case or upper case?
3. How do you get the ASCII value of any letter or number (alphanumeric) in python?
4. How do you get the alphanumeric value of an integer in the range of the ASCII table?
5. Can you print all of the ASCII values?
6. Explain what a cipher is?
7. Run the cipher program and enter this sentence: “Doubts may not be pleasant, but certainty is absurd.” What is the encrypted sentence?
8. What does this ‘Hello’.isalpha() do in python shell?
9. What is the syntax to check if it is numeric?
10. What does this ‘HELLO’.isupper() do in python shell?
11. Explain what this code snippet does and what the purpose is in cipher.py:

if num > ord('Z'):
   num -= 26
elif num < ord('a'):
   num += 26

12. Explain the function getKey().
13. Explain the function getTranslatedMessage(mode, message, key).

Homework
Explain Brute Force

List: FlashCards1_YI.py

Classwork:
More on spritesAndSound.py

Write a python/pygame program, FlashCards1_YI.py similar to previous program, mySpritesAndSound_YI.py. However, in this program, the user has to click on two matching cards. If the user guesses right, the sound should indicate so and so should the sound indicate when it is wrong.

flashCards

Note: there are libraries of sound files online. Look for the right one for your application.

Homework: Keep on reading chapter 19 – Sound and Images

Chapter 19 – Sound and Images link
Screen Shot 2014-04-28 at 7.05.14 AM

Final Project Proposal and Requirements

Final Project:

SUBMIT A PROPOSAL FOR MY APPROVAL. DO NOT START WORKING ON YOUR PROJECT. IF YOU HAVE INCOMPLETE ASSIGNMENTS, THEY HAVE TO BE FINISHED BEFORE YOU GET STARTED ON YOUR PROJECT BUT TALK TO ME ABOUT THEM.

  • The project can be a game that YOU created.
  • The project can be an application related to business, science, or any other subject you are interested on.
  • The project can be a program that was already assigned but you want to upgrade, modify or expand.
  • The project can be a pygame program or a python program.
  • If it is a pygame program, it must be animated. It must make use of list or dictionary.
  • If it is a python program, it must make use of list or dictionary.
  • The program must have good documentation.
  • The program has to be user friendly.
  • If the program uses other files, compress all of them into one file for submission.
  • Make sure you copy and paste the program on the post.
  • THIS PROJECT IS MEANT TO REPLACE THE WRITTEN FINAL EXAM ONLY IF YOU APPLY YOURSELF.
  • Khan Academy and Breakthrough Prize

    “From now until October 7, Khan Academy and Breakthrough Prize are seeking video submissions that explain a challenging and important concept or theory in mathematics, life sciences, or physics. If you’re between 13 and 18, and you have a passion for explaining ideas and concepts creatively, you can enter the Breakthrough Junior Challenge!
    Learn more about the Breakthrough Junior Challenge
    Not only can you dig into a topic that you’re passionate about, but there are also great prizes to be won, including a $250,000 scholarship for you, a $50,000 award for your teacher, and a state-of-the-art $100,000 science lab for your school. The winner will also be invited California, where the prize will be awarded in front of the superstars of science, Silicon Valley, and Hollywood.

    If you enter, you’ll view and assess other participants’ videos in a peer-to-peer review process. Submissions will then be assessed by leaders in science, technology, and education selected by Khan Academy and by Breakthrough Prize laureates. The judges will select a winner based on how engaging, illuminating, and creative their video is, and how challenging the concept is to understand.

    The deadline for submissions is October 7, so register today at www.breakthroughjuniorchallenge.org. We hope you’ll be inspired to get involved – and share your passion for understanding the world!

    Onward,

    Erin and the Khan Academy content team”

    PROMYS

    PROMYS provides a lively mathematical environment in which ambitious high school students explore the creative world of mathematics. Through their intensive efforts to solve a large assortment of unusually challenging problems in Number Theory, the participants practice the art of mathematical discovery – numerical exploration, formulation and critique of conjectures, and techniques of proof and generalization. More experienced participants may also study The Mathematics of Computer Graphics, Complex Analysis in Number Theory (Dirichlet’s theorem on arithmetic progressions), and Geometry and Symmetry. Problem sets are accompanied by daily lectures given by research mathematicians. In addition, a highly competent staff of 20 undergraduate counselors live in the residence halls and are always available to discuss mathematics with students. Advanced participants also develop independent research projects advised by research mathematicians. Special lectures by outside speakers offer a broad view of mathematics and its role in the sciences and in future career options.

    Screen Shot 2016-01-30 at 1.08.58 AM

    Pi Day 2014

    March 14th, 2014

    PI DAY!!

    Pi Day activity

    March 12th, 2014

    Friday is Pi Day – We will have a pi-day activity
    Starting tomorrow we are celebrating Pi day by writing a program to do one of the following:
    1. Calculate the digits of Pi to highest possible precision
    2. Illustrate how Pi works
    3. Illustrate how Pi was discovered

    The programs will be judge based on ingenuity and/or creativity.
    NOTE: You can use online resources to help you develop your program. You can not use already written programs.

    Screen Shot 2014-03-12 at 9.40.23 AM
    Classwork:
    Write a pygame program, YI_MazeBouncing.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.