GitHub - samcabano/python_fundamentals: Unit 1: Fundamentals of Programming in Python · GitHub
Skip to content

samcabano/python_fundamentals

Repository files navigation

Fundamentals of Python

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.

Unit 1 Portfolio

Complete collection: Unit 1 Repository

Introduction

  • Hello Turtle: Simple program using turtle graphics system.

Flow Control

  • How Many Trees?: Calculates the number of trees in Sacramento, explores flow control.

Conditionals and Lists

More Lists, and Introduction to Functions

  • 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.

Functions and Dictionaries

Strings and Exception Handling

  • 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.

Reading and Writing Files

Analysis and Reflection

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.

For example:

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 result

A 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 result

While 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.

About

Unit 1: Fundamentals of Programming in Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

Languages