Skip to content

Commit 0ab944a

Browse files
authored
Merge pull request #106 from PdxCodeGuild/colton-labs
Colton labs
2 parents e508e4d + 2ec68e0 commit 0ab944a

File tree

3 files changed

+217
-2
lines changed

3 files changed

+217
-2
lines changed

Code/colton/python/lab04.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,19 @@
3333
}
3434

3535

36+
def validate_card(prompt):
37+
card = input(prompt).upper().strip()
38+
while card not in card_values:
39+
card = input(prompt).upper().strip()
40+
return card
41+
3642
dealer_hand = random.randint(15, 23) # Generates likely hands for dealer
3743

3844

3945
cards = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"]
4046
random_card = random.choice(cards) # Generates card choice from list of cards
4147

4248

43-
44-
4549
total = 0
4650
while True:
4751
### This will get user input and actively add them together, if they enter a value that equals more than 21 than it will print an error

Code/colton/python/lab07.py

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
''' +-+#^#+--+#^#+--+#^#+-+
2+
Project: ROT Cipher ░░╚══╗░╔═╔════╝
3+
Version: 1.00 ╚═╦═╗╠═╩═╩╗╔═╦═╗
4+
Author: Colton Tatum ░░║▒╠╣▒▒▒▒╠╣▒║▒║
5+
Email: [email protected] ╔═╩═╝╠═╦═╦╝╚═╩═╝
6+
Date: 2/14/22 ░░╔══╝░╚═╚════╗
7+
+-+#^#+--+#^#+--+#^#+-+
8+
'''
9+
10+
# Program that prompts the user for a string, and encodes it with ROT13.
11+
# For each character, find the corresponding character, add it to an output string.
12+
13+
14+
15+
16+
17+
18+
19+
from string import ascii_letters, ascii_lowercase
20+
21+
22+
def rot13 (user_input, num):
23+
"""Encrypts letter by adding changing it to a defined letter at another index"""
24+
from string import ascii_lowercase
25+
26+
# create list with letters sorted starting with designated letter instead of a
27+
# I have no idea why it wouldn't get the last letter of the list without ascii_lowercase[-1]
28+
rot = list(ascii_lowercase[num:-1] +ascii_lowercase[-1] +ascii_lowercase[0:num])
29+
print(rot)
30+
index_nums = []
31+
rot_list = []
32+
33+
# get index value of user_input chars within ascii_lowercase
34+
for char in user_input:
35+
x = ascii_lowercase.index(char)
36+
index_nums.append(x)
37+
38+
print(index_nums)
39+
40+
# take index values and apply them to rot_list[index values] to get corresponding char
41+
for char in index_nums:
42+
x = rot[char]
43+
rot_list.append(x)
44+
45+
print(rot_list)
46+
print("".join(rot_list))
47+
48+
49+
def rot_decrypt (user_input, num):
50+
"""Encrypts letter by adding changing it to a defined letter at another index"""
51+
from string import ascii_lowercase
52+
53+
# create list with letters sorted starting with designated letter index value
54+
rot = list(ascii_lowercase[num:-1] +ascii_lowercase[-1] +ascii_lowercase[0:num])
55+
decrypted = []
56+
57+
# for char in user_input take the value of the corresponding rot, and apply that index value to the ascii_lowercase
58+
# append that char to a decrypted list
59+
for char in user_input:
60+
x = rot.index(char)
61+
b = ascii_lowercase[x]
62+
decrypted.append(b)
63+
64+
print(decrypted)
65+
print("".join(decrypted))
66+
67+
68+
69+
70+
71+
72+
73+
74+
# Encrypt user_input to rot_13
75+
while True:
76+
77+
user_phrase = input("Enter word to convert\n").lower().strip().replace(" ", "") # ensures input is a valid number
78+
if user_phrase.isalpha() == True:
79+
break
80+
else:
81+
print("Enter a valid input")
82+
continue
83+
84+
85+
# Designate amount of rotations for encryption
86+
while True:
87+
try:
88+
user_num = int(input("Enter number to determine starting letter for encryption\n"))
89+
break
90+
except ValueError:
91+
print("Enter valid input, 1-26")
92+
continue
93+
94+
95+
96+
rot13(user_phrase, user_num)
97+
98+
99+
# Decrypt back to ascii_lowercase
100+
while True:
101+
102+
user_phrase = input("Enter word to convert\n").lower().strip().replace(" ", "") # ensures input is a valid number
103+
if user_phrase.isalpha() == True:
104+
break
105+
else:
106+
print("Enter a valid input")
107+
continue
108+
109+
110+
# Enter amount of rotations to decrypt
111+
while True:
112+
try:
113+
user_num = int(input("Enter number to determine starting letter for encryption\n"))
114+
break
115+
except ValueError:
116+
print("Enter valid input, 1-26")
117+
continue
118+
119+
120+
rot_decrypt(user_phrase, user_num)
121+
122+
123+
124+

Code/colton/python/lab08.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
''' +-+#^#+--+#^#+--+#^#+-+
2+
Project: Peaks and Valleys ░░╚══╗░╔═╔════╝
3+
Version: 1.00 ╚═╦═╗╠═╩═╩╗╔═╦═╗
4+
Author: Colton Tatum ░░║▒╠╣▒▒▒▒╠╣▒║▒║
5+
Email: [email protected] ╔═╩═╝╠═╦═╦╝╚═╩═╝
6+
Date: 2/15/22 ░░╔══╝░╚═╚════╗
7+
+-+#^#+--+#^#+--+#^#+-+
8+
'''
9+
10+
11+
12+
13+
def peaks(data):
14+
"""Gets peaks in a list"""
15+
list = []
16+
for i, num in enumerate(data):
17+
try:
18+
if data[i] > data[i+1] and data[i] > data[i-1]:
19+
if data[i-1] == data[-1]:
20+
continue
21+
list.append(i)
22+
except IndexError:
23+
continue
24+
25+
return list
26+
27+
28+
29+
30+
def valleys(data):
31+
"""Gets valleys in a list"""
32+
list = []
33+
for i, num in enumerate(data):
34+
try:
35+
if data[i] < data[i+1] and data[i] < data[i-1]: # data[i-1] is looping back to the last position
36+
if data[i-1] == data[-1]:
37+
continue
38+
list.append(i)
39+
except IndexError:
40+
continue
41+
return list
42+
43+
44+
45+
46+
def peaks_and_valleys(data):
47+
"""Gets peaks and valleys of a list and returns a list"""
48+
list = []
49+
for i, num in enumerate(data):
50+
try:
51+
if data[i] > data[i+1] and data[i] > data[i-1]:
52+
if data[i-1] == data[-1]:
53+
continue
54+
list.append(num)
55+
56+
elif data[i] < data[i+1] and data[i] < data[i-1]:
57+
if data[i-1] == data[-1]:
58+
continue
59+
list.append(num)
60+
61+
62+
except IndexError:
63+
continue
64+
65+
return list
66+
# Ignore for now
67+
def draw_peaks_valleys(data):
68+
for num in data:
69+
if num == 1:
70+
print("""
71+
X""")
72+
if num == 2:
73+
print("""
74+
X
75+
X""", end="")
76+
return
77+
78+
79+
80+
data = [1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 5, 6, 7, 8, 9, 8, 7, 6, 7, 8, 9]
81+
82+
print(peaks(data), "Indices of Peaks")
83+
print(valleys(data), "Indices of Valleys")
84+
print(peaks_and_valleys(data),"Values of Peaks, and Valleys in order")
85+
86+
87+

0 commit comments

Comments
 (0)