Skip to content

Instantly share code, notes, and snippets.

View codetombomb's full-sized avatar
:octocat:

Tom Tobar codetombomb

:octocat:
View GitHub Profile
@codetombomb
codetombomb / hello_world.py
Created September 24, 2020 16:35
Conditionals 1
def main(a, b):
if a > b:
print("A is greater than b.")
elif a == b:
print("A is equal to b")
else:
print("A is less than b")
if __name__ == "__main__":
main(5, 10)
@codetombomb
codetombomb / hello_world.py
Created September 24, 2020 06:40
Conditionals
def forecast(rain_chance, temp):
if rain_chance >= 60 and temp > 70:
print(
f"With a {rain_chance}% chance of rain today, don't forget your umbrella!")
elif rain_chance <= 30 and temp < 80 and temp > 60:
print("Enjoy the beautiful weather today")
elif rain_chance >= 60 and temp < 40:
print("Its going to be a cold and wet day today. Dress appropriately and be safe out there.")
elif rain_chance == 0 and temp < 40:
@codetombomb
codetombomb / hello_world.py
Created September 24, 2020 05:42
Variable Number of Arguments
def tally_nums(*numbers):
total = 0
for n in numbers:
total += n
print(total)
if __name__ == "__main__":
tally_nums(1, 1, 1.3, 4.6)
tally_nums(4, 5, 6, 7, 8, 9)
@codetombomb
codetombomb / hello_world.py
Created September 24, 2020 05:40
Sum all nums
def tally_nums(*numbers):
total = 0
for n in numbers:
total += n
print(total)
if __name__ == "__main__":
tally_nums(1, 1, 1.3, 4.6)
tally_nums(4, 5, 6, 7, 8, 9)
@codetombomb
codetombomb / hello_world.py
Last active September 23, 2020 23:46
square funtion
def square(num):
answer = num * num
print(answer)
square(2)
square(4)
square(6)
@codetombomb
codetombomb / launch.json
Last active September 23, 2020 18:58
launch.json file
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "internalConsole"
}
@codetombomb
codetombomb / functions.py
Last active September 23, 2020 00:18
Starting a Python function
# This is a comment. Comments start with the '#'
# Function one (for demonstration purposes)
def function_name(parameter):
#This is the functions body
#The body is defined by the indention at the begining of the line
print(parameter)
# Function two
def function_two():
@codetombomb
codetombomb / Car.rb
Last active September 16, 2020 04:47
Adding class methods
class Car
attr_accessor :color, :year, :make, :model
@@all = []
def initialize(color, year, make, model)
@color = color
@year = year
@make = make
@model = model
@@all << self
end
@codetombomb
codetombomb / Car.rb
Last active September 16, 2020 04:42
Another Example for instance of self
class Car
attr_accessor :color, :year, :make, :model
def initialize(color, year, make, model)
@color = color
@year = year
@make = make
@model = model
end
def get_vin
@codetombomb
codetombomb / Car.rb
Last active September 16, 2020 04:27
Ruby Car Factory
class Car
attr_accessor :color, :year, :make, :model
def initialize(color, year, make, model)
# our instance variables are defined using a single @
@color = color
@year = year
@make = make
@model = model
end