From dfa95b85c3814a677c074be60d386f43e55138a1 Mon Sep 17 00:00:00 2001 From: Ganome Date: Mon, 17 May 2021 11:17:53 -0600 Subject: [PATCH] Updated PCC-Python Class --- python/PCC-python3/Chapter-01/Exercise-01.py | 6 +++ python/PCC-python3/Chapter-02/Exercise-02.py | 11 +++++ python/PCC-python3/Chapter-03/example.py | 26 +++++++++++ python/PCC-python3/Chapter-03/windspeed.py | 36 +++++++++++++++ python/PCC-python3/Chapter-06/car.py | 43 +++++++++++++++++ python/PCC-python3/Chapter-06/clock.py | 46 +++++++++++++++++++ python/PCC-python3/Chapter-06/computer.py | 36 +++++++++++++++ python/PCC-python3/Chapter-06/newpc.py | 10 ++++ python/PCC-python3/Chapter-06/thetime.py | 24 ++++++++++ .../murach-python/Section3/Chapter18/gui.py | 28 +++++++++++ 10 files changed, 266 insertions(+) create mode 100644 python/PCC-python3/Chapter-01/Exercise-01.py create mode 100644 python/PCC-python3/Chapter-02/Exercise-02.py create mode 100644 python/PCC-python3/Chapter-03/example.py create mode 100755 python/PCC-python3/Chapter-03/windspeed.py create mode 100644 python/PCC-python3/Chapter-06/car.py create mode 100644 python/PCC-python3/Chapter-06/clock.py create mode 100644 python/PCC-python3/Chapter-06/computer.py create mode 100644 python/PCC-python3/Chapter-06/newpc.py create mode 100644 python/PCC-python3/Chapter-06/thetime.py diff --git a/python/PCC-python3/Chapter-01/Exercise-01.py b/python/PCC-python3/Chapter-01/Exercise-01.py new file mode 100644 index 0000000..9f3ca37 --- /dev/null +++ b/python/PCC-python3/Chapter-01/Exercise-01.py @@ -0,0 +1,6 @@ +name = "David Billings" +location = "Colorado" + +print (f"Hello everyone, my name is {name} \nI just finished a Cyber-Security Bootcamp @ DU") +print (f"I am from %s.\nUsing formatted Strings is the way to go!!" %location) +print ("I have basic programming experience (Learn Python 3 The Hard Way)") diff --git a/python/PCC-python3/Chapter-02/Exercise-02.py b/python/PCC-python3/Chapter-02/Exercise-02.py new file mode 100644 index 0000000..9ccad97 --- /dev/null +++ b/python/PCC-python3/Chapter-02/Exercise-02.py @@ -0,0 +1,11 @@ +#Get user's string + +userString = input("Enter a string to start slicing: ") + +num1 = int(input ("Now enter Starting point of the slice: ")) #This technique is known as type-casting! +num2 = int(input ("Now pick where to end the slice: ")) #If you do not enter an integer, the program will crash + +print("The string was sliced at: %d & %d" % (num1, num2)) +#print(f"The string was sliced at: {num1} & {num2}") #This produces the exact same output as above! + +print("Your sliced string:\n", userString[num1:num2+1]) #We have to add 1 to the end because the Start slice is inclusive. The end slice is EXCLUSIVE! \ No newline at end of file diff --git a/python/PCC-python3/Chapter-03/example.py b/python/PCC-python3/Chapter-03/example.py new file mode 100644 index 0000000..6064a7d --- /dev/null +++ b/python/PCC-python3/Chapter-03/example.py @@ -0,0 +1,26 @@ +# Introduction to Python Programming +# Lesson 03 Assignment +# Sample Solution + +# Please note that this program takes advantage of the fact that +# once a condition is met, the if structure is exited. This +# allows me to not need a lower limit in my conditions because +# if the speed were below the minimum for that Category, the +# program would have already printed the result and exited. + +speed = eval(input("Please enter the wind speed: ")) + +if speed < 74: + print ("This is not a hurricane") +elif speed <= 95: + print ("Category 1") +elif speed <= 110: + print ("Category 2") +elif speed <= 130: + print ("Category 3") +elif speed <= 155: + print ("Category 4") +else: + print ("Category 5") + + diff --git a/python/PCC-python3/Chapter-03/windspeed.py b/python/PCC-python3/Chapter-03/windspeed.py new file mode 100755 index 0000000..7c01d05 --- /dev/null +++ b/python/PCC-python3/Chapter-03/windspeed.py @@ -0,0 +1,36 @@ +#!/usr/bin/python3 + +#This programs calculates what level a hurricane is based on Wind Speed +def hurricaneSpeeds(): + try: + windSpeed = int(input("Please enter the current MPH in wind speed: ")) + + while windSpeed: + if windSpeed <= 73 and windSpeed > 0: + print ("This isn't even a hurricane you Nancy!!") + break #Without this break line, it will SPAM text at you in the console!!! + elif windSpeed > 73 and windSpeed <= 95: + print ("You've got yourself a Category 1 hurricane.") + break #Without this break line, it will SPAM text at you in the console!!! + elif windSpeed >= 96 and windSpeed <= 110: + print ("This is a category 2 hurricane") + break #Without this break line, it will SPAM text at you in the console!!! + elif windSpeed >= 111 and windSpeed <= 130: + print ("Getting up there, Category 3!!!") + break + elif windSpeed >=131 and windSpeed <= 155: + print("Hope your safe, this is a Category 4!") + break + elif windSpeed > 155: + print("If your not safe somewhere, bend over and kiss your ass goodbye. This is a Category FIVE!!") + break + else: + print("Hurricanes can't have winds less than ZERO miles per hour!!!\n*** Try Again ***") + hurricaneSpeeds() + break + + except: + print("Please enter a number: 75, 120, 200, etc...") + hurricaneSpeeds() + +hurricaneSpeeds() \ No newline at end of file diff --git a/python/PCC-python3/Chapter-06/car.py b/python/PCC-python3/Chapter-06/car.py new file mode 100644 index 0000000..3168591 --- /dev/null +++ b/python/PCC-python3/Chapter-06/car.py @@ -0,0 +1,43 @@ +"""This will define the car class""" + +class car: + def __init__(self): + self.__wheels = 4 + self.__windows = 6 + self.__doors = 4 + + +class computer: + def __init__(self): + self.__CPU = 0 + self.__RAM = 0 + self.__STORAGE = 0 + self.__FIREWALL = 0 + self.__AV = 0 + self.__OS = 0 + self.__NETWORK = 0 + + def setCPU(self, speed): + self.__CPU = speed + def setRAM(self, ram): + self.__RAM = ram + def setSTORAGE(self, storage): + self.__STORAGE = storage + def setOS(self, os): + self.__OS = os + def setNETWORK(self, network): + self.__NETWORK = network + + def newComputer(self, cpu, ram, storage, os, network): + self.__CPU = cpu + self.__RAM = ram + self.__STORAGE = storage + self.__OS = os + self.__NETWORK = network + + +myPC = computer() +myPC.setCPU(500) +myPC.setRAM(32) + +print(myPC._computer__CPU, myPC._computer__RAM) diff --git a/python/PCC-python3/Chapter-06/clock.py b/python/PCC-python3/Chapter-06/clock.py new file mode 100644 index 0000000..392ffc6 --- /dev/null +++ b/python/PCC-python3/Chapter-06/clock.py @@ -0,0 +1,46 @@ +class Clock: + def __init__(self): + self.__hour = 0 + self.__minute = 0 + self.__second = 0 + + def setTime(self, hour, minute, second): + self.__hour = hour + self.__minute = minute + self.__second = second + + def tick(self): + self.__second = self.__second + 1 + if (self.__second == 60): + self.__second = 0 + self.__minute = self.__minute + 1 + if (self.__minute == 60): + self.__hour = self.__hour + 1 + self.__minute = 0 + if (self.__hour == 24): + self.__hour = 0 + + def printTime(self): + print("The time is - ", self.__hour, ":", self.__minute, ":", self.__second) + + def setSeconds(self, second): + if int(second) >= 0: + if int(second) <= 59: + self.__second = second + else: + return + def setMinutes(self, minute): + if int(minute) >= 0: + if int(minute) <= 59: + self.__minute = minute + else: + return + def setHours(self, hour): + self.__hour = hour + #NOW WE'LL DEFINE OUR GETTERS + def getSeconds(self): + return self.__second + def getMinutes(self): + return self.__minute + def getHours(self): + return self.__hour diff --git a/python/PCC-python3/Chapter-06/computer.py b/python/PCC-python3/Chapter-06/computer.py new file mode 100644 index 0000000..b72d702 --- /dev/null +++ b/python/PCC-python3/Chapter-06/computer.py @@ -0,0 +1,36 @@ +class Computer: + def __init__(self): + self.__CPU = 0 + self.__CORES = 0 + self.__POWER = self.__CORES * self.__CPU + self.__RAM = 0 + self.__STORAGE = 0 + self.__FIREWALL = 0 + self.__AV = 0 + self.__OS = 0 + self.__NETWORK = 0 + + def setCPU(self, speed): + self.__CPU = speed + def setRAM(self, ram): + self.__RAM = ram + def setSTORAGE(self, storage): + self.__STORAGE = storage + def setOS(self, os): + self.__OS = os + def setNETWORK(self, network): + self.__NETWORK = network + + def newComputer(self, cpu, cores, ram, storage, os, network): + self.__CPU = cpu + self.__CORES = cores + self.__POWER = cpu * cores + self.__RAM = ram + self.__STORAGE = storage + self.__OS = os + self.__NETWORK = network + + def printSpecs(self): + print("Current computer Specs are as follows:\nCPU: ", self.__CPU, "Mhz @", self.__CORES, "Total Power: ", self.__POWER, "\nRAM: ", self.__RAM, "\nStorage: ", self.__STORAGE, "Terabytes\nOperating System: ", self.__OS, "\nNetwork Connection: ", self.__NETWORK) + + diff --git a/python/PCC-python3/Chapter-06/newpc.py b/python/PCC-python3/Chapter-06/newpc.py new file mode 100644 index 0000000..f130efa --- /dev/null +++ b/python/PCC-python3/Chapter-06/newpc.py @@ -0,0 +1,10 @@ +from computer import Computer + +myPC = Computer() + +#myPC.setCPU(500) +#myPC.setRAM(32) +#print(myPC._Computer__CPU, myPC._Computer__RAM) + +myPC.newComputer(2750, 6, 128, 8, "linux", "gigabit") +myPC.printSpecs() \ No newline at end of file diff --git a/python/PCC-python3/Chapter-06/thetime.py b/python/PCC-python3/Chapter-06/thetime.py new file mode 100644 index 0000000..e438ae7 --- /dev/null +++ b/python/PCC-python3/Chapter-06/thetime.py @@ -0,0 +1,24 @@ +from clock import Clock + +localTime = Clock() + +localTime.printTime() +localTime.setTime(23, 59, 59) +localTime.printTime() + +#print (localTime._Clock__second) #THIS IS how you access private or mangled variable names + +#localTime.setSeconds("37") +#localTime.setHours(4) +#localTime.setMinutes(20) +localTime.tick() +localTime.printTime() + +#print ("The class for is ",localTime, localTime.__class__) #This line prints out the memory address + +control = 1 +loop = 150 +while control < loop: + localTime.printTime() + localTime.tick() + control = control + 1 diff --git a/python/murach-python/Section3/Chapter18/gui.py b/python/murach-python/Section3/Chapter18/gui.py index e69de29..ba87da0 100644 --- a/python/murach-python/Section3/Chapter18/gui.py +++ b/python/murach-python/Section3/Chapter18/gui.py @@ -0,0 +1,28 @@ +#!/usr/bin/python3 + +import tkinter as tk +from tkinter import ttk + +root = tk.Tk() + +#Name the window and set Geometry +root.title("Ganome's First Window") +root.geometry("300x200") + +#Create a frame +frame = ttk.Frame(root, padding="10 10 10 10") +frame.pack(fill=tk.BOTH, expand=True) + +#make a second frame +frame2 = ttk.Frame(root, padding="10 10 10 10") +frame2.pack(fill=tk.BOTH, expand=True) + +#create buttons +button1 = ttk.Button(frame, text="Click Me!!") +button2 = ttk.Button(frame2, text="Don't Click Me!!") + +button1.pack() +button2.pack() + + +root.mainloop()