Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joe Ray #430

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
8 changes: 8 additions & 0 deletions day_1/ex1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#puts "Hello World!"
#puts "Hello Again"
#puts "I like typing this."
#puts "This is fun."
#puts "Yay! Printing."
#puts "I'd much rather you 'not'."
#puts 'I "said" do not touch this.'
puts "Make your script print another line."
9 changes: 9 additions & 0 deletions day_1/ex2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# A comment, this is so you can read your program later.
# Anything after the # is ignored by ruby.

puts "I could have code like this." # and the comment after is ignored

# You can also use a comment to "disable" or comment out a piece of code:
# puts "This won't run."

puts "This will run."
4 changes: 4 additions & 0 deletions day_1/ex3-1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This is for Study Drills question 3

puts 6+5-2+20/2>=5
# per terminal this = true
23 changes: 23 additions & 0 deletions day_1/ex3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
puts "I will now count my chickens:"
# Brackets let you insert Ruby comps into text strings
puts "Hens #{25.0 + 30.0 / 6.0}"
puts "Roosters #{100.0 - 25.0 * 3.0 % 4.0}"
# Shows a string
puts "Now I will count the eggs:"
# Shows just the computation
puts 3.0 + 2.0 + 1.0 - 5.0 + 4.0 % 2.0 - 1.0 / 4.0 + 6.0
# List everything out since it's contained in string, even the numbers
puts "Is it true that 3 + 2 < 5 - 7?"
# Shows computed equation
puts 3.0 + 2.0 < 5.0 - 7.0
# Lines 14 and 15, same as lines 3 and 4
puts "What is 3 + 2? #{3.0 + 2.0}"
puts "What is 5 - 7? #{5.0 - 7.0}"
# string
puts "Oh, that's why it's false."
# string
puts "How about some more."
# Similar to 3, 4, 14, and 15. Shows Question string trailed by computed answer
puts "Is it greater? #{5.0 > -2.0}"
puts "Is it greater or equal? #{5.0 >= -2.0}"
puts "Is it less or equal? #{5.0 <= -2.0}"
42 changes: 42 additions & 0 deletions day_1/ex4-1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# STUDY DRILLS:

#1. Explain error in your own words

# -The variable carpool_capacity on line 14 was not properly defined on line
# 7. (This is what this error message means but without seeing the OG code
# this is the best guess at lines etc)

#1. Using 4.0

# -It could be necessary, but with the current numbers it's not. I say it could
# be because, in very few situations it could impact the number of people
# you could transport. For example, assuming there were
# (9 drivers * 2.3 space_in_a_car the carpool_capacity would = 20.7). In this
# situation you would round down to 20 people that you could
# transport because you most likely wouldn't have less than one whole person.
#
# -If it was just 4 and not 4.0 then the resulting number for carpool_capacity
# would be a whole number with no decimal so. 120 not 120.0
#
#2. Not reall a queston, more of a statement on floating points.
#
#3. See ex4.rb file.
#
#4. Statement about what "=" is called and that it gives data names.
#
#5. Statement about name of "_"
#
#6. See calculations below.

i = 10
x = 2
j = 5
people_invited = 50
people_who_showed_up_at_party = 20
number_of_people_at_party = people_invited - people_who_showed_up_at_party
number_of_invitations_made = people_invited


puts "There will be #{number_of_people_at_party} people at the party on Saturday."
puts "I sent out #{number_of_invitations_made} invitations to my friends and family."
puts i * j / x
24 changes: 24 additions & 0 deletions day_1/ex4.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# The value or equivalent for cars is now defined as 100.
cars = 100
# The value or equivalent for space_in_a_car is now defined as 4.0.
space_in_a_car = 4.0
# The value or equivalent for drivers is now defined as 30.
drivers = 30
# The value or equivalent for passengers is now defined as 90.
passengers = 90
# The value or equivalent for cars_not_driven is now defined as cars(90)-drivers(30).
cars_not_driven = cars - drivers
# The value or equivalent for cars_driven is now defined as drivers(30).
cars_driven = drivers
# The value or equivalent for carpool_capacity is now defined as cars_driven(30) * space_in_a_car(4.0).
carpool_capacity = cars_driven * space_in_a_car
# The value or equivalent for average_passengers_per_car is now defined as passengers(90) / cars_driven(30).
average_passengers_per_car = passengers / cars_driven


puts "There are #{cars} cars available."
puts "There are only #{drivers} drivers available."
puts "There will be #{cars_not_driven} empty cars today."
puts "We can transport #{carpool_capacity} people today."
puts "We have #{passengers} to carpool today."
puts "We need to put about #{average_passengers_per_car} in each car."
21 changes: 21 additions & 0 deletions day_1/ex5.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name = 'Zed A. Shaw'
age = 35
height = 74
height_in_centimeters = height * 2.54 # New variable (Study Drills #2)
weight = 180
weight_in_kilograms = weight * 0.453592 # New variable (Study Drills #2)
eyes = 'Blue'
teeth = 'White'
hair = 'Brown'

puts "Let's talk about #{name}."
puts "He's #{height} inches tall."
puts "He's #{weight} pounds heavy."
puts "Actually that's not too heavy."
puts "He's got #{eyes} eyes and #{hair} hair."
puts "His teeth are usually #{teeth} depending on the coffee."
#
puts "He's #{height_in_centimeters} centimeters tall." # Proof of new variable
puts "He's #{weight_in_kilograms} kilograms heavy." # Proof of new variable

puts "If I add #{age}, #{height}, and #{weight} I get #{age + height + weight}."
27 changes: 27 additions & 0 deletions day_1/ex6-1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Exercise 6 Study Drills from LRTHW webpage.

# 1. Check ex6.rb
#
# 2. Lines:
# 10, 15, 17, and...
# 13 - I'm not sure if you would count this since it's a print command of a
# "string inside of a string". I'm adding it since the directions state to list
# "ALL the places where a string is put inside a string."
#
# 3. Yes, I'm sure. The only other possible lines are the following:
#
# 4 - I didn't count this because "technically" it's an integer inside of a string.
# 21 - I didn't count this because "technically" it's a boolean inside of a string.
#
# 4. You are adding the two strings together.
#
# 5. The single and double-quotes work "mostly" the same way. Normally you don't see them
# when using the puts command and running the file in ruby BUT, you can show
# them in ruby if you put them inside of each other. It works both ways as well.
# For example,
# if you want to see '' printed > puts "I like the 'way' you move."
# if you want to see "" printed > puts 'I like the "way" you move.'

# The differences between the two is that the Single-Quotes can't hold/execute
# string interpolation inside of the them. They also can't hold/print escape
# sequences directly.
29 changes: 29 additions & 0 deletions day_1/ex6.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Defining the variable value.
types_of_people = 10
# Creating string with a different string inside of it via a "#{}"
x = "There are #{types_of_people} types of people."
# Creating a string
binary = "binary"
# Creating a string
do_not = "don't"
#Creating string with a 2 different strings inside of it via a "#{}"
y = "Those who know #{binary} and those who #{do_not}."
# prints the string attached to the variable "X" and "y"on the following line
puts x
puts y
# prints string with "x" stirng inside of it.
puts "I said: #{x}."
# prints string with "y" stirng inside of it.
puts "I also said: '#{y}'."
# Defines variable value to "false"
hilarious = true
# Creates a string with a false variable inside of it.
joke_evaluation = "Isn't that joke so funny?! #{hilarious}"
# Prints above stated string with variable in it.
puts joke_evaluation
# Creates a string "w" variable.
w = "This is the left side..."
# Creates a string "e" variable.
e = "a string with a right side."
# Prints thestrings attached to the "w" and "e" variablein the PEMDAS order.
puts w + e
21 changes: 21 additions & 0 deletions day_1/ex7-1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Exercise 7 Study Drills from LRTHW webpage.

# 1. gets.chomp is a two part method.
# gets(get string) method - retrieves user input via a string. When the user
# types a string and hits enter this enter is included in the users strings
# as a (\n) newline.
#
# chomp method - removes the (\n) newline character at the end of a string(s)
#
# 2. Yes, see bottom of <ex7.rb> file.
#
# 3. Please see form below:

print "What color is your hair? "
hair = gets.chomp
print "How high can you jump? "
height = gets.chomp
print "How many large pizzas can you eat? "
pizza_count = gets.chomp

puts "So, you're hair color is #{hair}, you can jump #{height} high, and eat #{pizza_count} large pizza(s)."
15 changes: 15 additions & 0 deletions day_1/ex7.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
print "How old are you? "
age = gets.chomp
print "How tall are you? "
height = gets.chomp
print "How much do you weight? "
weight = gets.chomp

puts "So, you're #{age} old, #{height} tall and #{weight} heavy."

# Answer to second question from strudy drills on webpage.

# After you run it, type your name(hit enter) then it will insert your name
# into string when it's displayed/printed.
name = gets.chomp
puts "Hello #{name}, nice to meet you!"
4 changes: 2 additions & 2 deletions day_1/exercises/interpolation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
speedy = "quick red fox"
slow_poke = "lazy brown dog"

p # YOUR CODE HERE
p "The #{speedy} jumped over the #{slow_poke}"

# Write code that uses the variables below to form a string that reads
# "In a predictable result, the tortoise beat the hare!":
slow_poke = "tortoise"
speedy = "hare"

# YOUR CODE HERE
p "In a predictable result, the #{slow_poke} beat the #{speedy}!"
7 changes: 4 additions & 3 deletions day_1/exercises/loops.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

# Write code that prints the sum of 2 plus 2 seven times:
7.times do
# YOUR CODE HERE
p 2 + 2
end

# Write code that prints the phrase 'She sells seashells down by the seashore'
# ten times:
# YOUR CODE HERE
10.times do
puts 'She sells seashells down by the seashore'
end
12 changes: 9 additions & 3 deletions day_1/exercises/numbers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
p 2 + 2

# Write code that prints the result of 7 subtracted from 83:
p #YOUR CODE HERE
p 83 - 7

# Write code that prints the result of 6 multiplied by 53:
# YOUR CODE HERE
p 6 * 53

# Write code that prints the result of the modulo of 10 into 54:
# YOUR CODE HERE
# Since I'm not sure if you're asking for 54 mod 10 or 10 mod 54
# I'm going to put both. I thinking you mean the first so I'll
# list that first as my official "answer", ha.


p 54 % 10
p 10 % 54
4 changes: 2 additions & 2 deletions day_1/exercises/strings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
p "Alan Turing"

# Write code that prints `Welcome to Turing!` to the terminal:
p #YOUR CODE HERE
p "Welcome to Turing!"

# Write code that prints `99 bottles of pop on the wall...` to the terminal:
# YOUR CODE HERE
p "99 bottles of pop on the wall..."
15 changes: 8 additions & 7 deletions day_1/exercises/variables.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# In the below exercises, write code that achieves
# the desired result. To check your work, run this
# file by entering the following command in your terminal:
# file by entering the following command in your terminal:
# `ruby day_1/exercises/variables.rb`

# Example: Write code that saves your name to a variable and
Expand All @@ -11,19 +11,20 @@
# Write code that saves the string 'Dobby' to a variable and
# prints what that variable holds to the terminal:
house_elf = "Dobby"
# YOUR CODE HERE
p house_elf

# Write code that saves the string 'Harry Potter must not return to Hogwarts!'
# and prints what that variable holds to the terminal:
# YOUR CODE HERE
elf_command = "Harry Potter must not return to Hogwarts!"
p elf_command

# Write code that adds 2 to the `students` variable and
# prints the result:
students = 22
# YOUR CODE HERE
p students
x = students + 2
p x

# Write code that subracts 2 from the `students` variable and
# prints the result:
# YOUR CODE HERE
p students
j = students - 2
p j
23 changes: 23 additions & 0 deletions day_1/questions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,39 @@

1. How would you print the string `"Hello World!"` to the terminal?

- puts `"Hello World!"`

1. What character is used to indicate comments in a ruby file?

- it's called an octothorpe or pound character

1. Explain the difference between an integer and a float?

- integer has to be a whole number, float contains floating decimal place so it doesn't have to be a whole number

1. In the space below, create a variable `animal` that holds the string `"zebra"`

- animal = "zebra"

1. How would you print the string `"zebra"` using the variable that you created above?

- puts animal

1. What is interpolation? Use interpolation to print a sentence using the variable `animal`.

- It's a method that allows you to embed/place Ruby code inside of a string by using the pound character with brackets `#{}` .(Assuming you mean string interpolation)

- ```Ruby
animal = "zebra"
puts "I would love to pet a #{animal}."
```

1. What method is used to get input from a user?

- The `gets` method. The specific method we used earlier was `gets and chomp`
methods combined. Which looks like this `gets.chomp`

1. Name and describe two common string methods:

- `.length` method - returns the string length of a variable in ruby.
- `.upcase` method - turns all letters in a string to uppercase.
Loading