# Homework 3-1

Due April 9, 2013, 2:25 pm

For the first part of this assignment, we will review and practice Python skills by doing a lot simple tasks which cultimate in a function that encrypts a message. Complete these tasks by answering the questions and filling out the stencil code in `HW3-1.py`. You will find instructions in the form of comments.

The idea of this simple encryption scheme is this: You keep a secret number, called `n`. You take a message, and change each letter to a new one that is `n` letter(s) ahead of it on the alphabet (wrapping around to A if you go past Z). For example, encrypting

`"to be or not to be"`
using number `1` will give you
`"up cf ps opu up cf"`

To decrypt a message, someone will need to know your secret number, and reverse this process.

A random guessing game consists of 100 coin flips. The score is the number of heads. For this part, you want to answer the question: if I play this game 1000 times, what percentage of times do I get a score higher than 62? Write a function called `coinflipper()` to answer this question. Put it at the bottom of your `HW3-1.py` file.

Here are steps to guide you through the process of answering this question. If you are confident enough, you should try to break the task down into steps yourself.

• Flip a coin; print `0` if it comes out tails or `1` otherwise.
• Repeat 100 times. Instead of printing `0`s and `1`s, keep a count of how many `1`s you have seen. That is your score of one game. Print the score.
• Now repeat the game 1000 times. Instead of printing out the scores, keep a count of how many of the scores are 62 or greater. Print that number. Calculate the percentage.

Reminders:

• Do not forget to write `import random` at the beginning of your program. Then `random.random()` will return a random number between 0 (inclusive) and 1 (exclusive) for you every time it is called.
• You can have one for-loop within another.
• The following for-loop executes its body 100 times:
`for i in range(0,100):`
• Make sure you are keeping the counts in the right way (i.e., think about when you should reset your count and when you shouldn't).

## Handin

Rename your program file to `YourName_HW3-1.py` and email it to `cs0931handin@gmail.com`.