Weeks 1 to 2 exercises

This commit is contained in:
YOUR NAME 2017-08-14 11:34:33 +10:00
commit c9d6b32012
46 changed files with 807 additions and 0 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

59
Example/calculator.rb Normal file
View file

@ -0,0 +1,59 @@
# This method ask the user what type of calculation they would like to perform
# It returns the operation or an error for erroneous entry
def request_calculation_type
puts "Type 1 to add, 2 to subtract, 3 to multiply, or 4 to divide two numbers: "
operation_selection = gets.to_i
if operation_selection == 1
"add"
elsif operation_selection == 2
"subtract"
elsif operation_selection == 3
"multiply"
elsif operation_selection == 4
"divide"
else
"error"
end
end
# This method performs the requested calculation
# It returns the result of the calculation
def calculate_answer(operator, a, b)
if operator == "add"
a + b
elsif operator == "subtract"
a - b
elsif operator == "multiply"
a * b
elsif operator == "divide"
a / b
end
end
run_calculator = 1
while run_calculator == 1
current_calculation = request_calculation_type()
if current_calculation == "error"
puts "I do not understand this type of calculation... Can we try again?"
else
puts "What is the first number you would you like to #{current_calculation}: "
first_number = gets.to_i
puts "What is the second number you would like to #{current_calculation}: "
second_number = gets.to_i
answer = calculate_answer(current_calculation, first_number, second_number)
puts "The answer is #{answer}"
puts "Type 1 to run another calcution or 2 to end: "
run_calculator = gets.to_i
end
end

7
Example/cloop Normal file
View file

@ -0,0 +1,7 @@
x = [1, 2, 3, 4, 5]
for i in x do
puts i
end
puts "Done!"

3
Example/cloop.rb Normal file
View file

@ -0,0 +1,3 @@
loop do
puts "suck my dick"
end

9
Example/example.rb Normal file
View file

@ -0,0 +1,9 @@
def age(ntt)
puts "My age is #{ntt}"
puts "My age is #{ntt}"
puts "My age is #{ntt}"
end
age(ntt)

5
Example/for in Normal file
View file

@ -0,0 +1,5 @@
arr = [1, 2, 3]
for a in arr
puts "element #{a}"
end

5
Example/forin Normal file
View file

@ -0,0 +1,5 @@
arr = [1, 2, 3]
for a in arr
puts "element #{a}"
end

16
Example/gender & temp.rb Normal file
View file

@ -0,0 +1,16 @@
puts "what is your gender?"
random = gets.chomp.to_i
if female == "female"
puts "what is temp?"
if "female" above 20 = "wear dress"
if random <= 20
puts "wear shorts!"
else random > 20
puts "wear pants!"
end
male = "wear shorts!" "wear pants!"
def gender(male, female)

18
Example/gender.rb Normal file
View file

@ -0,0 +1,18 @@
puts "what is your gender?"
random = gets.chomp.to_i
if female > 20 = "wear dress!"
else random < 20
puts "wear pants!"
puts "what is temp?" #and above 20
#if "female" above 20 = "wear dress"
#if random <= 20
# puts "wear shorts!"
#else random > 20
#puts "wear pants!"
end
#def gender(male, female)

8
Example/temp.rb Normal file
View file

@ -0,0 +1,8 @@
puts "how hot is it?"
random = gets.chomp.to_i
if random <= 20
puts "wear shorts!"
else random > 20
puts "wear pants!"
end

BIN
My website/.DS_Store vendored Normal file

Binary file not shown.

0
My website/about.html Normal file
View file

BIN
My website/css/.DS_Store vendored Normal file

Binary file not shown.

0
My website/css/style.css Normal file
View file

BIN
My website/images/.DS_Store vendored Normal file

Binary file not shown.

View file

0
My website/index.html Normal file
View file

0
My website/js/script.js Normal file
View file

7
README.md Normal file
View file

@ -0,0 +1,7 @@
# exercises-
# exercises-
# exercises-
# exercises1
# exercises1
# exercises1
# exercises1

BIN
array/.DS_Store vendored Normal file

Binary file not shown.

64
array/Atm.rb Normal file
View file

@ -0,0 +1,64 @@
=begin
-CREATE MINIMUM VIABLE PRODUCT
create a terminal app that behaves like a real life ATM
-greeting --this one
-pin
-accounts
-language
-withdrawal --this one
-check balance --this one
-deposit --this one
------Make them methods, multiple times so loops, gets.chomp, arrays,
=end
prompt_for_more_banking = puts "Would you like to do anything else?"
#present user with "options- deposit, check balance, withdrawal"
balance = 100
greeting = #start page and this gets looped if doesn't enter somehting valid
puts "We are ghouls, we will take your soul out then charge you a fees, it's your choice how we devour you!"
#loop variable
def options_loop
puts """
If deposit press 1
If check balance press 2
If withdrawal press 3
"""
end
options_loop
user_input = gets.chomp.to_i
if user_input == 1
puts "How much would you like to deposit?" #
deposit_amount = gets.chomp.to_i
balance = balance + deposit_amount #0 is 0 balance plus the amount the user deposits
puts "You've deposited $#{deposit_amount}" #tells user how much they've deposited
puts "Thank you for your monies! #{options_loop}."
puts "You're new balance is #{balance}"
elsif user_input == 2
puts "checking balance... "
puts "You have $#{balance}" #tells user their balance
prompt_for_more_banking
options_loop
elsif user_input == 3
if balance <= 0
puts "You have $#{balance} left, we took it all! you poor shit"
prompt_for_more_banking
options_loop
#{options_loop}"
else
puts "How much would you like to withdrawl? You have $#{balance} dollars"
withdrawal = gets.chomp.to_i
puts "You've withdrawn $#{withdrawal}"
puts "You have $#{balance - withdrawal} left..for us to steal"
puts "Make sure you give us more than you take or we'll chase you!"
prompt_for_more_banking
options_loop
end
else
puts "That's not a valid number!"
options_loop
end
#create a loop called options that returns deposit, check balance, withdrawal
# exit = puts "see ya biaatch!"

16
array/Untitled.rb Normal file
View file

@ -0,0 +1,16 @@
shoppingList = [("store_Items"), ("store_Items2")]
puts "What do you want to add to your shopping list?"
store_Items = gets.chomp.to_s
puts ("You've added #{store_items} in your cart")
puts "Do you wish to add anything else?"
store_Items2 = gets.to_s
puts ("You've added #{store_Items2} in your cart")
#save store_Items2, store_Items in shoppingList
puts "Would you like to view your items?"
store_Items.include? "yes"
puts "Thanks for using us!"
puts "#{shoppingList}"

9
array/alphabet/al.rb Normal file
View file

@ -0,0 +1,9 @@
alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n","o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
firstLetter = alphabet[0]
alphabet.push ("i know the best words!")
# '<<' = '.push'
alphabet.each do |letter|
puts "This letter is #{letter}"
end

View file

@ -0,0 +1 @@
class.dog

View file

@ -0,0 +1 @@
recipe_1_ingredients = []

View file

@ -0,0 +1,21 @@
something = "poo"
=begin case something
when "pear"
puts "something is a pear"
when "apple"
puts "something is an apple"
when "orange"
puts "something is an orange"
else
puts "That ain't fruit yo mama gave you!"
end
=end
# COUNTER
counter = 0
while counter <= 100..1000 do
puts counter
counter += 23
end

21
array/new shopping.rb Normal file
View file

@ -0,0 +1,21 @@
shoppingList =[
"hummus",
"Avocado",
"ben n jerrys",
"marajuana",
"Guacamole",
l =
[
"candy",
"lollipop",
"jelly"]
]
shoppingList = gets.chomp.to_i.to_s
chosenItem = shoppingList[4]
chosen_Stripper = strippers[2]
puts "Want ot add an item to your Shopping list?"
puts "#{shoppingList}"
puts "The best thing to have in your tummy is #{chosenItem}"
puts "Take a wild ride with #{chosen_Stripper} in it"

33
array/trent.rb Normal file
View file

@ -0,0 +1,33 @@
# ask a question
# based of the answer of that question we want too do either:
# withdrawal
# deposit
answer = 0
until answer == 3
system("clear")
puts "hey, do you want to (1) withdraw, or (2) deposit or (3) exit"
answer = gets.chomp.to_i
balance = 100
if answer == 1
system("clear")
puts "how much would you like to withdraw?"
balance = balance - gets.chomp.to_i
puts "your new balance is #{balance}"
sleep(3)
system("clear")
elsif answer == 2
system("clear")
puts "how much would you like to deposit?"
balance = balance + gets.chomp.to_i
puts "your new balance is #{balance}"
sleep(3)
system("clear")
else
system("clear")
puts "fuck off"
sleep(3)
system("clear")
end
end

17
array/you guessed it.rb Normal file
View file

@ -0,0 +1,17 @@
shoppingList =[
"chips",
"water",
"hookers",
"marajuana",
"Guacamole",
alcohol =
[
"rum",
"whiskey",
"whatever"]
]
chosenDip = shoppingList[4]
list_Item = shoppingList.length + alcohol.length - 1
puts "The best dip in the world is #{chosenDip}"
puts "Your shopping list has #{list_Item} in it"

33
atm_classes.rb Normal file
View file

@ -0,0 +1,33 @@
#create accounts
#class Account
#def initialize()
#Create an Atm
class Atm
#how do we descibe the atm
def initialize(location, brand, current_cash, pin)
@location = location
@brand = brand
@current_cash = current_cash
@balance = 100
@pin = []
end
# what can an atm do?
def dispense(amount)
@balance = @balance - amount
puts "I gave you #{amount} from #{@location} atm, the new balance is #{@balance}"
end
end
broadway_atm = Atm.new("broadway", "commonscum", 100, 1111)
ultimo_atm = Atm.new("ultimo", "peasants", 1000, 1111)
yomama_bank = Atm.new("sydney", "yomama", 100000, 1111)
#Asks for pin
broadway_atm.dispense(70)
ultimo_atm.dispense(19000)
yomama_bank.dispense(23330)

33
cars.rb Normal file
View file

@ -0,0 +1,33 @@
class Car
#How do we describe the car
def initialize(type, colour, brand, year)
@type = type
@colour = colour
@brand = brand
@year = year
@petrol = 100
end
#what can it do
# getter
def colour
@colour
end
# setter
def colour=(colour)
@colour = colour
end
def go(time, speed)
puts "move at #{time} + #{speed}"
end
end
honda = Car.new("4 wheeler", "red", "honda", 2000)
honda.go("1pm", "100Km/hr")
# puts the color of the car
puts honda.colour
honda.colour = "blue"
puts honda.colour

50
celsiusclass.rb Normal file
View file

@ -0,0 +1,50 @@
=begin
Create a Celsius class, that takes the temperature as a parameter.
Remember to use the `initialize` method
Define a method that returns the temperature in Fahrenheit. For the conversion we can use the formula
`temperature*1.8 + 32`. Round up the result so it doesnt contain any decimal values.
Use the round method
Create a script that prompts you to fill in the temperature for each day of the week (Monday - Sunday)
and for the inputs 16, 17 18, 18, 21, 16, 19 prints out the following output:
=end
=begin
Class weekdays_from_C_to_F
def initialize(mon, tue, wed, thu, fri, sat, sun)
@mon = mon
@tue = tue
@wed = wed
@thu = thu
@fri = fri
@sat = sat
@sun = sun
=end
x = 0
weekday = 1..7
#weekday is equal to mon-sun and needs to run through a loop
"mon" = 1
"tue" = 2
"wed" = 3
"thu" = 4
"sat" = 5
"sun" = 6
#make a weekday variable that then loops a question that gets the answer from
#the user and converts it to Fahrenheit
until x == 7, weekday ==7
puts "what is temperature in Celsius on #{weekday}?"
temp_in_C = gets.chomp.to_i
puts "the temperature on #{weekday} is #{temp_in_C*1.8 + 32} in degrees F."
x = x + 1
weekday = weekday + 1
end

21
classes_objects.rb Normal file
View file

@ -0,0 +1,21 @@
#Create a person app
class.Personfactory
#How do we describe it
def initialize(name, personality, age, hair_colour)
@name = name
@personality = personality
@hair_colour = hair_colour
@age = age
#What can we do
end
def talk(sentence)
puts sentence
end
end
omar = Personfactory.new("Omar", "Pretty cool", "Brown", 19)
omar.name("yoo")

28
day.rb Normal file
View file

@ -0,0 +1,28 @@
class Day
#hoe do we describe it
def initialize(name, temperature)
@name = name
@temperature = temperature
end
end
class Temperature
def initialize(celsius)
@celsius = celsius
end
attr_accessor :temperature
def to_f
@celsius * 1.8 + 32
end
end
box = []
7.times do (number)
puts "hey, what was the temperature on day #{number}"
x = Day.new(number)emperature. new,

11
dog_classes.rb Normal file
View file

@ -0,0 +1,11 @@
class dog
def initialize(colour, breed , age, name)
@age = age
@colour =
@breed = breed
@name = name
def sit
end

10
gems.locked Normal file
View file

@ -0,0 +1,10 @@
GEM
specs:
PLATFORMS
ruby
DEPENDENCIES
BUNDLED WITH
1.15.3

4
gems.rb Normal file
View file

@ -0,0 +1,4 @@
require 'artii'
a = Artii::Base.new :font => 'slant'
puts a.asciify("WAZZZUUUUUUPPP!!")

0
penis_program/1.8.0 Normal file
View file

View file

@ -0,0 +1 @@

View file

@ -0,0 +1,40 @@
#build an app that solves a problem
#with 3 classes
#one gem
#ever wanted to solve the problem of your friends being not funny,
#they can't yo mama you when your mamadeserves it
#create classes that consists of the level of harassment of a yommama joke you wanted
#choices of easy, medium, hard
class begin_the_crazy
def initialize(easy, medium, hardcore)
@easy_harassment = easy
@medium_harassment= medium
@hardcore_harassment = hardcore
end
class easy_harassment
def easy(fat, ugly, dumb)
@fat = fat
@ugly = ugly
@dumb = dumb
end
#fat when dracula sucked her blood, he got diabetes
#ugly bob the builder saw her and said "I can't fix that"
#old so old that when she farts, dust comes out
class medium_harassment
def medium(whore, hairy, stupid)
#fat when she died she broke the stairway to heaven
#puts hairy, she so hairy you got carpet burn when she gave birth to you
#puts ugly when she looked out of the window, she got arrested for mooning
class hardcore_harassment
def hardcore()
#fat when she pressed up on an elevator, it goes down
#old when I told her to act her age, she died
puts "You little shit, you want to be harassed by yo mama's fat, ugly or dumb ass?"

View file

@ -0,0 +1,39 @@
#_app_id = 8761fe27
#_app_key = eb9bc332198f1609d3f41f6e426fc670
# config/initializers/yummly.rb
require 'httparty'
require 'yummly'
Yummly.configure do |config|
config.app_id = "8761fe27"
config.app_key = "eb9bc332198f1609d3f41f6e426fc670"
config.use_ssl = true # Default is false
end
result = Yummly.search('carrot')
#puts 10 recipe names with that keyword
puts result.collect { |recipe| recipe.name}
#puts result.total # returns 43350
#puts result.size(10) # returns 10
#have user pick one option
#display the options with array index visible
#gets.chomp users option into a variable .to_i
# get the receipe name and url
# display the ingredients for that one recipe
##{}
#url = ""
#result2 = Yummly.search('carrot')
puts result2.collect {|recipe| recipe.ingredients}
#puts result.collect { |recipe| recipe.ingredients}
#/s"hello"

0
penis_program/review.rb Normal file
View file

125
penis_program/review2.rb Normal file
View file

@ -0,0 +1,125 @@
#this is a comment
apples = 5
name = "omar1" #any character ""
good_laa = ["hdhdd", "wuswu"]
countries_that_sell_arms_to_saudis = ["Canada", "divided_states_of_murica"]
countries_that_sell_arms_to_saudis.insert(2, "Britain")
countries_that_sell_arms_to_saudis.delete_at(1)
puts countries_that_sell_arms_to_saudis
#while loops
i = 0
while i <= 5
puts i
i = i + 1
end
#do loops
goals =+ 1
loop do
goals += 1
puts "you scored"
break if goals > 5
end
puts "you won"
#each loops
["tom", "dick", "harry", "ghoul"].each do |name|
if name.start_with?("g")
puts "Hello, #{name}"
else
puts "error"
end
end
#switch cases, more than 2 options
capacity = 20
case capacity
when 0
puts "You ran out of petrol"
when 1..20
puts "hurry fill up"
when 21..70
puts "You running good"
else
puts "Error, invalid value, Fuck off! (#{capacity})"
end
#blocks
def my_block
puts "step 1"
yield #break
puts "steps 3"
end
my_block do
puts "step 2"
end
#letters = ["a", "b", "c"]
#puts letters[1]
##ARRAYS
friends = {"key" => "value", "key2" => "value2"}
=begin
dan = {"forest lodge" => "123 fake steet", "3829849" => "ahhhaahs.org"}
dictionary = {"facacious" => "exaggerating something", => "canada" => "a magical place"}
puts dictionary.["facacious"]
puts dictionary
dictionary.delete("canadia")
puts dictionary
puts dictionary.length
dictionary.clear
dictionary["cat"] = "new animal"
puts dictionary
=end
a = "a letter"
b = "a letter"
c = :a_letter
d = :a_letter
#tinder app
user_1 = {:swipe => "left", "swipe" => "right"} #shit long code
user_2 = {swipe:"left", swipe:"right"}
puts user_2
luke = {:ssn => "238384747"}
puts luke.ssn
#use blocks, get.chomp, yield
#create a choose your own adventure
#wake up
#choose torch, knife or banana
##if torch, puts you've turn it on, choose move towards bushy area or one with faint sounds
##a spider is on your face
##do you leave it as your new pet, or slap your face trying to get it.
## you now are dead, the spider is poisonous,
##and you slapped yourself unconcious and lions have eaten you
###if knife
###choose move forward, or bend over to look for other items
###if move forward, you've see a faint light and feel domething on your leg,
### do you walk towards the light or check to see what is on your Feet
### the knife has a lifeforce and started stabbing you, you're dead
####if banana
#### choose do you eat banana because you are hungry or move forward
#### your choices totally mattered, lions nearby smelt the banana and have eaten you,
####your dead, if you moved forward they smelt that you have a banana and have eaten you

View file

@ -0,0 +1,17 @@
def show(size = "small")
case size
when "small"
"8=D"
when "medium"
"8==D"
when "large"
"8====D"
when "super_large"
"8=======D"
when "kevin"
"8========================================================D"
end
end
puts show("kevin")

74
restaurant_class.rb Normal file
View file

@ -0,0 +1,74 @@
# I run a restaurant and am rich, wants to be richer
# 1 want to be richer. My staff costs $3 an hair_colour
#Write some code to let me fire them
=begin class Robot_service
attr_accessor :burgers, :chips, :drink, :flurries
#give class info on what it is doing
def initialize(burgers, chips, drink, flurries)
@burgers = burgers#chicken, lamb, or veggie because you're a hippy
@chips = chips#potato or sweet potato
@drink = drink#orange, cocaine, some sugar_filled_shit
@flurries = flurries#oreo because I can code now and have the munchies
end
def order(order)
puts "You've ordered #{@burgers}, #{@chips}, #{@drink}, #{@flurries}, Now pay or I'll fucking kill you!"
sleep(3)
system("clear")
end
# # IMPORTANT: The getter and setter methods below for `burgers`
# # are automatically generated when we typed up the top
# # in the class `attr_accessor :burgers`
#
#getter
##def burgers
#return @burgers
#end
#
#setter
#def burgers=(burgers)
# @burgers = burgers
#end
end
order_for_clownface = Robot_service.new("chicken", "maccas chips", "Fresh OJ", "Oreo")
# puts order_for_clownface.order(1)
# puts order_for_clownface.methods
order_for_clownface.burgers = ("vegie")
order_for_clownface.order(1)
=end
#Greeting
puts "Welcome to shitsandwich! How may we shit in your food today?"
puts "Lets start with burgers, type 'fresh from a goats ass poo or FFAGAP, matured sun-dried poo or MSP, diarrohea or D'"
the_answer1 = gets.chomp
if
the_answer1 == 'FFAGAP';'MSP';'D';
puts"What drink would you like? We are exclusively offering pee or P, goats milk or GM"
the_answer2 = gets.chomp
if
the_answer2 == 'P'; 'GM';
puts "Thank you, I am a robot and even I hate you!"
else
puts "fuck off"
end
end
# burgers = gets.chomp.uppercase
#{}
# puts order_for_clownface.burgers

1
shopping_list Submodule

@ -0,0 +1 @@
Subproject commit 8aede175eb89c6c26b4271a8fba3525e944dd293