Skip to content
Draft

test #127

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions code/Kevin/Python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bot_config.py
98 changes: 98 additions & 0 deletions code/Kevin/Python/Calculations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
'''
This program calculates voltage, current, and resistance for a circuit.
'''

class Circuit:
def __init__(self, voltage={'?':'?'}, resistance={'?':'?'}, current={'?':'?'}):
self.voltage = {'Voltage':voltage}
self.resistance = {'Resistance':resistance}
self.current = {'Current':current}

def add_to_resistance(self, resistance_total, resistance_series, resistance_parallel):
self.resistance['Resistance'] = {'Rt':resistance_total}
rs = 1
rp = 1
for value in resistance_series:
self.resistance['Resistance']['Rs'+str(rs)] = value
rs += 1
for value in resistance_parallel:
self.resistance['Resistance']['Rp'+str(rp)] = value
rp += 1

def add_to_voltage(self, voltage, current, resistance_series, resistance_parallel):
self.voltage['Voltage'] = {'Vt': voltage}
vp_value = 0
vs = 1
vp = 1
for ohms in resistance_series:
self.voltage['Voltage']['Vs'+str(vs)] = (ohms * current)
vp_value += ohms * current
vs += 1
vp_value = round(voltage - vp_value, 8)
for ohms in resistance_parallel:
self.voltage['Voltage']['Vp'+str(vp)] = vp_value
vp += 1
return vp_value

def add_to_current(self, current, resistance_series, resistance_parallel, voltage_parallel):
self.current['Current'] = {'S1':(1000 * current)}
cs = 1
cp = 1
for ohms in resistance_parallel:
if ohms == 0:
break
self.current['Current']['Cp'+str(cp)] = 1000 * round(voltage_parallel / ohms, 8)
cp += 1



def print_circuit(input_dict):
for key, value in input_dict.items():
print('--', key, '--')
for nested_key, nested_value in value.items():
print(nested_key, ' : ', nested_value)


circuit_1 = Circuit()
# print(f'''
# Circuit 1
# Voltage = {circuit_1.voltage}
# Total resistance = {circuit_1.resistance}
# Current = {circuit_1.current}''')

def circuit_builder(voltage_int, resistance_series_str, resistance_parallel_str):

voltage = voltage_int
resistance_series = resistance_series_str.split(',')
resistance_series = [int(i) for i in resistance_series]


resistance_parallel = resistance_parallel_str.split(',')
resistance_parallel = [int(i) for i in resistance_parallel]



resistance_parallel_total = 0
if 0 not in resistance_parallel:
for ohms in resistance_parallel:
resistance_parallel_total += 1/ohms
resistance_parallel_total = 1/resistance_parallel_total

resistance_total = round(sum(resistance_series) + resistance_parallel_total, 8)

current = round(voltage / resistance_total, 8)

circuit_1.add_to_resistance(resistance_total, resistance_series, resistance_parallel)
voltage_parallel = circuit_1.add_to_voltage(voltage, current, resistance_series, resistance_parallel)
circuit_1.add_to_current(current, resistance_series, resistance_parallel, voltage_parallel)
# print(voltage_parallel)

return circuit_1




# circuit_builder(10,'300,850','600,450')
# print_circuit(circuit_1.voltage)
# print_circuit(circuit_1.resistance)
# print_circuit(circuit_1.current)
110 changes: 110 additions & 0 deletions code/Kevin/Python/discord_bot_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
'''
Bot time.
'''
import random

from bot_config import bot_key, server_id, server_general_channel
from pick6 import play_pick_6

import nextcord
from nextcord import Interaction, Intents, SlashOption
from nextcord.ext import commands

from Calculations import circuit_builder

from resis_color_calc import band_calculator, band_1_and_2, band_multiplier,band_tolerance


intents = nextcord.Intents.default()
intents.message_content = True








bot = commands.Bot(command_prefix='!', intents=intents)

#Say hello when bot comes online.
prime_join_list = [
'LIBERTY PRIME IS ONLINE.', 'ALL SYSTEMS NOMINAL.', 'WEAPONS: HOT.',
'''Voice module online.
Audio functionality test initialized.
Designation: Liberty Prime.
Mission: the liberation of Anchorage, Alaska.
Primary Targets: any and all Red Chinese invaders.
Emergency Communist Acquisition Directive: immediate self destruct.
Better dead, than Red.''',

]

@bot.event
async def on_ready():

general_channel = bot.get_channel(server_general_channel)

await general_channel.send(random.choice(prime_join_list).upper())



#Say command make
@bot.slash_command(name='say', description='Make Liberty Prime say something', guild_ids=[server_id])
async def say_func(interaction: Interaction, msg:str):
await interaction.response.send_message(msg)


#Circuit calculator
@bot.slash_command(name='calc', description='Make Liberty Prime calc something', guild_ids=[server_id])
async def calc_func(interaction: Interaction, volt:int, series:str, parallel:str):
circuit_1 = circuit_builder(volt, series, parallel)
response_f_str = f'''
Here are your results.
-- VOLTAGE --
{circuit_1.voltage['Voltage']}
-- RESISTANCE ohms--
{circuit_1.resistance['Resistance']}
-- CURRENT mA--
{circuit_1.current['Current']}
'''
await interaction.response.send_message(response_f_str)


#Play pick6
@bot.slash_command(name='pick6', description='Play Pick6! Input the number of times you would like to play, and how much money you got', guild_ids=[server_id])
async def pick6_func(interaction: Interaction, number_of_plays:int, balance:int):
result = play_pick_6(number_of_plays, balance)
pick_6_return = f'''
Here are your results.
Balance {result['balance']}
Expenses {result['expenses']}
Earnings {result['earnings']}
'''

await interaction.response.send_message(pick_6_return)

contacts_description = f'''
This is the description for the...
contacts slash command'''
@bot.slash_command(name='contacts', description=contacts_description)
async def contacts_func(interaction: Interaction,
number: int = SlashOption(name="picker", choices={'one': 1, "two": 2, "three": 3}, )):


# await interaction.response.Slash
await interaction.response.send_message(str(number))


@bot.slash_command(name='resistor_band_calc', description='Calc resistors')
async def resistor_calc(interaction: Interaction,
color_1: str = SlashOption(name="color_1", choices={'black' : 'black','brown': 'brown','red': 'red','orange': 'orange','yellow': 'yellow','green': 'green','blue': 'blue','violet':'violet','grey': 'grey','white': 'white'},),
color_2: str = SlashOption(name="color_2", choices={'black' : 'black','brown': 'brown','red': 'red','orange': 'orange','yellow': 'yellow','green': 'green','blue': 'blue','violet':'violet','grey': 'grey','white': 'white'},),
color_3: str = SlashOption(name="color_3", choices={'black' : 'black','brown': 'brown','red': 'red','orange': 'orange','yellow': 'yellow','green': 'green','blue': 'blue','violet':'violet','grey': 'grey','white': 'white','gold': 'gold','silver': 'silver'},),
color_4: str = SlashOption(name="color_4", choices={'brown': 'brown','red': 'red','green': 'green','blue': 'blue','violet': 'violet','grey': 'grey','gold': 'gold','silver': 'silver'},),
):
await interaction.response.send_message(band_calculator(color_1, color_2, color_3, color_4))

bot.run(bot_key)


74 changes: 74 additions & 0 deletions code/Kevin/Python/pick6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'''
This program will play pick 6 however many times the user inputs.
'''

import random

#Declare a function for making a list of 6 ints between 0 and 100.
def pick_6_list_generator():
list_of_6 = []
for x in range(6):
list_of_6.append(random.randint(1, 99))
return list_of_6

#Declare a function for playing pick 6
def play_pick_6(user_int, balance=0):
#Declare a list variable for our winning numbers and our playing numbers
winning_numbers = []
playing_numbers = []

#Declare a variable for our earnings, starting at zero.
earnings = 0

#Declare a variable for our expenses, starting at zero.
expenses = 0

#Declare a variable to return lists.
numbers_over_time = []

#Declare a variable that's a dictionary containing our winning information based on how many matches we get.
winnings_dict = {
0:0,
1:4,
2:7,
3:100,
4:50000,
5:1000000,
6:25000000

}



#Create our winning list.
winning_numbers = pick_6_list_generator()

#For loop for playing pick6 the amount of times the user inputs.
for x in range(user_int):
winnings_dict_lookup = 0 #Declare or reset a variable to store winnings per iteration.
index_iteration = 0 #Declare or reset a variable for looping through the winning numbers.
expenses += 2


playing_numbers = pick_6_list_generator() #Overwrite "player_numbers" list with a new set of numbers.
numbers_over_time.append(playing_numbers) #Add playing numbers to a list to return
# print(winning_numbers)
# print(playing_numbers)

#For loop for comparing "playing_numbers" with "winning_numbers"
for num in playing_numbers: #"num" will become each item in "playing_numbers" one at a time.
if num == winning_numbers[index_iteration]: #And if "num" matches the value at the index of 0 with "winning_numbers,"
winnings_dict_lookup += 1 # add 1 to "winning_dict_lookup."
index_iteration += 1 #Add 1 to "index_iteration" so that the next loop will compare sequential indexes of "winning_numbers."
earnings += winnings_dict[winnings_dict_lookup]
# print(winnings_dict_lookup)
balance = (balance - expenses) + earnings
#Return a dictionary of the results.
return {
"balance":balance,
"expenses":expenses,
"earnings":earnings,
"winning numbers":winning_numbers,
"your numbers":numbers_over_time

}
31 changes: 31 additions & 0 deletions code/Kevin/Python/resis_color_calc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'''
This program calculates resistors via their color bands
'''

band_1_and_2 = {'black' : '0','brown': '1','red': '2','orange': '3','yellow': '4','green': '5','blue': '6','violet':'7','grey': '8','white': '9'}

band_multiplier = {'black' : 1,'brown': 10,'red': 100,'orange': 1000,'yellow': 10000,'green': 100000,'blue': 1000000,'violet':10000000,'grey': 100000000,'white': 1000000000,'gold': 0.1,'silver': 0.01}

band_tolerance = {'brown': ['+-1%',1.01, 0.99],'red': ['+-2%',1.02, 0.98],'green': ['+-0.5%', 1.005, 0.995],'blue': ['+-0.25%', 1.0025, 0.9975],'violet': ['+-0.1%', 1.001, 0.999],'grey': ['+-0.05%', 1.0005, 0.9995],'gold': ['+-5%', 1.05, 0.95],'silver': ['+-10%', 1.10, 0.90]}

def band_calculator(color_1, color_2, color_3, color_4):
band_str =''
band_value = int(band_1_and_2[color_1] + band_1_and_2[color_2])
print(band_value, type(band_value))
band_value = band_value * band_multiplier[color_3]
print(band_value)
if band_value > 1000000000:
band_value *= .000000001
band_str = 'G'
elif band_value > 1000000:
band_value *= 0.000001
band_str = 'M'
elif band_value > 1000:
band_value *= 0.001
band_str = 'k'
return_f_str = f'''
Your resistor is {round(band_value, 4)}{band_str} Ohms with a tolerance of {band_tolerance[color_4][0]},
which is between {round(band_value * band_tolerance[color_4][2], 4)}{band_str} Ohms and {round(band_value * band_tolerance[color_4][1], 4)}{band_str} Ohms.'''
return return_f_str


22 changes: 22 additions & 0 deletions code/lauren/flask/my_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from flask import Flask, render_template

app = Flask(__name__)

posts = [
{
'title': "Foods you'll slap your mother for",
'author': "Jimmy John",
'date': "January 25th",
'body': "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Egestas sed tempus urna et pharetra pharetra massa massa ultricies. Iaculis nunc sed augue lacus viverra vitae. Arcu ac tortor dignissim convallis aenean et tortor at risus. Nunc scelerisque viverra mauris in. Nisl nunc mi ipsum faucibus vitae aliquet nec. Ultrices eros in cursus turpis massa. At risus viverra adipiscing at in tellus integer feugiat. Orci a scelerisque purus semper eget duis at tellus at. Libero volutpat sed cras ornare arcu dui vivamus arcu felis."
}, {

}

]



@app.route('/')
def home():
return render_template('index.html', posts=posts)

5 changes: 5 additions & 0 deletions code/lauren/flask/static/desktop_styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@media only screen and (min-width: 1000px){
body{
background-color: gray;
}
}
9 changes: 9 additions & 0 deletions code/lauren/flask/static/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

body{
background-color: wheat;
}

ul{
list-style: none;
}

21 changes: 21 additions & 0 deletions code/lauren/flask/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Blog</title>
</head>
<body>
<h1>Parenting Hacks</h1>

{% for post in posts %}
<ul>
<li>
{{post.author}}
</li>
</ul>
{% endfor %}

</body>
</html>
Empty file added code/lauren/python/.emv
Empty file.
Loading