Updated PCC-Python Class
This commit is contained in:
parent
7530150136
commit
dfa95b85c3
6
python/PCC-python3/Chapter-01/Exercise-01.py
Normal file
6
python/PCC-python3/Chapter-01/Exercise-01.py
Normal file
@ -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)")
|
||||
11
python/PCC-python3/Chapter-02/Exercise-02.py
Normal file
11
python/PCC-python3/Chapter-02/Exercise-02.py
Normal file
@ -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!
|
||||
26
python/PCC-python3/Chapter-03/example.py
Normal file
26
python/PCC-python3/Chapter-03/example.py
Normal file
@ -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")
|
||||
|
||||
|
||||
36
python/PCC-python3/Chapter-03/windspeed.py
Executable file
36
python/PCC-python3/Chapter-03/windspeed.py
Executable file
@ -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()
|
||||
43
python/PCC-python3/Chapter-06/car.py
Normal file
43
python/PCC-python3/Chapter-06/car.py
Normal file
@ -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)
|
||||
46
python/PCC-python3/Chapter-06/clock.py
Normal file
46
python/PCC-python3/Chapter-06/clock.py
Normal file
@ -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
|
||||
36
python/PCC-python3/Chapter-06/computer.py
Normal file
36
python/PCC-python3/Chapter-06/computer.py
Normal file
@ -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)
|
||||
|
||||
|
||||
10
python/PCC-python3/Chapter-06/newpc.py
Normal file
10
python/PCC-python3/Chapter-06/newpc.py
Normal file
@ -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()
|
||||
24
python/PCC-python3/Chapter-06/thetime.py
Normal file
24
python/PCC-python3/Chapter-06/thetime.py
Normal file
@ -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
|
||||
@ -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()
|
||||
Loading…
x
Reference in New Issue
Block a user