Attached are examples of small projects written in Python, all of which demonstrating basic Python fundamentals. Contents of the portfolio are organized chronologically by the primary fundamental(s) explored, and link to the raw code of each project. Each of the following pieces were created to practice and learn a focused concept of Python.
Complete collection: Unit 1 Repository
- Hello Turtle: Simple program using turtle graphics system.
- How Many Trees?: Calculates the number of trees in Sacramento, explores flow control.
- Password Generator: Generates two passwords utilizing lists, flow control, and conditionals.
- Rock, Paper, Scissors: Simple game that utilizes conditionals to determine the winner.
- Comma Code: Function turns list values into a formatted string.
- Collatz Sequence: Function requests an integer input, which is evaluated and returned as 1.
- Character Picture Grid: Function returns a picture drawn by lists of text characters.
- Substitution Cipher: Decrypts 'bkftazdaowe' to 'pythonrocks' with dictionaries and conditionals.
- Caesar Cipher: Encrypts plain text by shifting the alphabet 13 letters.
- Caesar Cipher Rotations: Decrypts text by printing all possible rotations of a Caesar Cipher.
- Scrambled Key Decryption: Decrypts ciphered text against a key of scrambled alphabet.
- Scrambled Key Encryption: Encrypts plain text by using a key of scrambled alphabet.
- Encryption and Decryption: Prompts the user to enter a key, gives the user the option to encrypt plain text or decrypt a coded message.
- Password Manager: Utilizes multiple functions, dictionaries, lists, strings, and conditionals to store account passwords, encrypt and generate passwords, update passwords, and copy passwords to clipboard.
- Store Your Favorite Number: Prompts user to enter their favorite number, storing it in a file.
- Display Your Favorite Number: Reads the file and prints the user's favorite number.
The most comprehensive and challenging project I completed in Unit 1 was the creation of a Password Manager, which incorporates each major concept of the course thusfar. I am proud of the code I produced for this assignment, as I feel it displays the most complex functions of anything we have practiced in Unit 1. This project taught me the importance of having organized code with detailed comments, as it required the definition of several variables and functions. To complete this project, I drew a flowchart indicating each desired function of the program, then implemented a function one by one. During the process, I learned it is important to run your code between each change, otherwise it is difficult to find the source of a coding error.
On the other hand, I would remove the cipher code listed under "Functions and Dictionaries", as it is redundant of the encryption and decryption code used in later projects. While writing code for various encryption and decryption exercises, I found it challenging to decide between the use of dictionaries, lists, or strings to assign encryption key values. By practicing with each format, I found the use of strings for this task allowed for more effective and dynamic code.
A dictionary was used in my Substitution Cipher:
key = {"a" : "o", "b" : "p", "c" : "q", "d" : "r", "e" : "s",
"f" : "t", "g" : "u", "h" : "v", "i" : "w", "j" : "x",
"k" : "y", "l" : "z", "m" : "a", "n" : "b", "o" : "c",
"p" : "d", "q" : "e", "r" : "f", "s" : "g", "t" : "h",
"u" : "i", "v" : "j", "w" : "k", "x" : "l", "y" : "m",
"z" : "n"}
def decrypt(str, key):
result = ""
for i in str:
result = result + key[i]
return resultA list was used in my Caesar Cipher to shift the index of a phrase by a specified number:
def encrypt(original, shift):
output = []
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for letter in original.lower():
index = alphabet.index(letter)
newIndex = (index + shift) % 26
result = alphabet[newIndex]
output.append(result)
return''.join (output)Strings were used in my Scrambled Key projects to compare corresponding index values between the alphabet and a scrambled key:
alphabet = ' abcdefghijklmnopqrstuvwxyz'
key = 'mwgp bdzxrylacsokjfhtnueivq'
def encrypt(string):
result = ""
for letter in string:
if letter in alphabet:
index = alphabet.index(letter)
result = result + key[index]
return resultWhile each example effectively encrypts or decrypts a string, the use of strings as a key allowed more flexibility in changing the key or accepting a user inputted key. Therefore, I found this code to be an improvement from previous strategies. Because of this experience, I feel my Password Manager is better formulated than older pieces because it contains improved code over the course of learning more Python techniques. For this reason, I feel my earlier pieces can be enhanced and expanded upon.
Altogether, Python has proven to be a straightforward and easy-to-use programming languange. In my opinion, it is equally, if not more, versatile and comprehensive than prior languages I have learned.
