Python Project – Simple One

* Dear reader, you may consider re-sizing screen smaller than 90%; potentially removing the need to scroll right to view the code (I’ve re-written it with more vertical lines to make it more visual-friendly).

# Inspired by Andy Sterkowitz (GitHub post, 3 Levels of Portfolio Projects. https://github.com/andysterks/three-levels-of-projects; 3 Types of Projects That Will Make You a Programmer. https://www.youtube.com/watch?v=RYE0QQKJI9o).

# Reinforcing/refining Python fundamentals and problem-solving

# KIV enhance speed by replacing <if> + <elif> + <else> loops with hash/lookup tables e.g. dictionaries or tuples (see Nicholas Obert. Nov 1, 2021. https://betterprogramming.pub/get-rid-of-excessive-if-else-statements-with-lookup-and-hash-tables-c7dbed808996; Parewa Labs Pvt Ltd. accessed 1 Aug 2022. Python Lists Vs Tuples. https://www.programiz.com/python-programming/list-vs-tuples).

# Algorithm (problem-solving recipe/logic) uses: risk classification, test grading, commission amounts etc.

***

Given the below, create a programme to provide estimated license fees.

V. Anton Spraul. 2012. Think like a programmer : an introduction to creative problem solving. San Franciso. No Starch Press. p. 68 (book teaches thru C++)
def biz_license_cost():
    
    # prints only once
    print("Welcome to your yearly",end=" ") # same line
    print("business licence cost estimator!")
    print() # prettier layout
    
    '''
    Extended comments
    Completed - 2022 Jul 29
    
    Lines 40 to 46 
    <while True> + <try> + <except> + <else> 
    with <float>, for decimals:
    validates user input without crashing. 
    
    Lines multiple <break> 
    ensures the loop ends and exits the programme. 
    
    Line 59 <else> 
    resolves negative number input. 
    
    Line 64 <else> 
    covers final scenario for sales_amount > 500000, 
    and provides licence cost.
    
    Note to self
    Ensure alignment: <try> + <except> + <else>.
    <finally>, unused, is only other 
    part of this Exception process. 
    
    Further study
    Al Sweigart. 2019. accessed 2022 Jul 29. 
    San Francisco. No Starch Press. 
    Automate the Boring Stuff with Python, 2nd Edition. 
    Chapter 8. 
    https://automatetheboringstuff.com/2e/chapter8/. 
    '''
    
    while True: 
        try:
            sales_amount = float(input("Enter positive sales_amount $:"))
        except:
            print("Do only enter +ve",end=" ")
            print("amount without symbols")
        else:
            if 0 < sales_amount <= 50000:
                print("License -> $25",end=" ")
                print("/ Cat One")
                break
            elif (50000 < sales_amount <= 150000):
                print("License -> $200",end=" ")
                print("/ Cat Two")
                break
            elif (150000 < sales_amount <= 500000):
                print("License -> $1000",end=" ")
                print("/ Cat Three")
                break
            else:
                if int(sales_amount) < 0:
                    print("License -> None:",end=" ")
                    print("please reconsider your business options.")
                    break
                else:
                    print("License -> $5000",end=" ")
                    print("/ Cat Four")
                    break
        
biz_license_cost() # run function
Sample output = )

Encrypt PDF -> Python

version 3 -> 21 May 2022

# Uses -> protects data/info; pair with data concealment and/or operate as partial pillar for honeypot (decoy and possible booby-trap)

# You would need a Python interpreter on your device. For Windows consider the below methods (Sorry Mac/Linux, you have search for the answers…):

For a Python programming project (under Singapore University of Technology and Design, SUTD) in 2021, I tried unsuccessfully to generate random passwords and store them encrypted in a text (.txt) file.

Recently though, I managed to successfully complete part of the concept by encrypting PDF files with the PyPDF2 library/package (at time of writing -> v1.27.9; https://pypi.org/project/PyPDF2/ -> Please take note that the name is case sensitive i.e. Upper-Lower-Upper-Upper-Upper-Number because typing a different case means it is a different library altogether).

Kudo and thanks to my project teammate who had referred us to Krish Naik’s YouTube channel! I eventually found his Pdf Password Protection Using Python. 13 Feb 2021. https://www.youtube.com/watch?v=JhabusIJZ3I there.

Naik’s video led me to his GitHub link – https://github.com/krishnaik06/Pdf-Encryption/blob/main/Pdf%20Password%20Protection%20Using%20Python.ipynb. This I modified, and thus far I’ve encrypted three PDF files.

Prep work before executing the code:

After executing the code, please store the Python file in a secure/encrypted folder because the password is plaintext and hence open to hackers.

Related