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"
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.
0
if it comes out tails or 1
otherwise.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.Reminders:
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.for i in range(0,100):
Rename your program file to YourName_HW3-1.py
and email it to cs0931handin@gmail.com
.