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

Kaelin Sleevi #70

Open
wants to merge 52 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
9ce3f4c
Initial commit
KaelinSleevi Jun 8, 2022
9bb4b30
Exercise 2
KaelinSleevi Jun 8, 2022
8f9f2f2
Exercise 3
KaelinSleevi Jun 8, 2022
4aa5c89
Exercise 4
KaelinSleevi Jun 8, 2022
6572efd
Exercise 5
KaelinSleevi Jun 8, 2022
f70388b
Exercise 6
KaelinSleevi Jun 8, 2022
6d22c6e
Exercise 7
KaelinSleevi Jun 8, 2022
91d8a23
section one work and answers
KaelinSleevi Jun 8, 2022
8578abc
add vocabulary for section 2
KaelinSleevi Jun 11, 2022
a2098eb
add work on exercise 29: what if?
KaelinSleevi Jun 11, 2022
028a996
add work on exercise 30: else and if
KaelinSleevi Jun 11, 2022
8f9e963
add work on exercise 31: making decisions
KaelinSleevi Jun 11, 2022
b0a3d1b
update answers on reflections for section 2
KaelinSleevi Jun 11, 2022
e15aaa9
add ruby in 100 minutes work
KaelinSleevi Jun 11, 2022
6c50fed
add reflection answers section 2
KaelinSleevi Jun 11, 2022
056dcc4
add if statement answers section 2
KaelinSleevi Jun 11, 2022
f8abed0
Update reflection.md
KaelinSleevi Jun 11, 2022
83fc367
Update reflection.md
KaelinSleevi Jun 11, 2022
e9a57d8
Update reflection.md
KaelinSleevi Jun 11, 2022
f5f88f7
Update reflection answers
KaelinSleevi Jun 11, 2022
5b9915e
update answers for section 1: a good first program
KaelinSleevi Jun 12, 2022
d0749ae
update answers for section 2: comments in code
KaelinSleevi Jun 12, 2022
e92ccb3
update answers for section 3: numbers and math
KaelinSleevi Jun 12, 2022
a2dc25d
update answers for section 4: variables and names
KaelinSleevi Jun 12, 2022
c3a9666
update answers for section 5: strings
KaelinSleevi Jun 12, 2022
0c18f00
update answers for section 6: more strings
KaelinSleevi Jun 12, 2022
c1d67a4
update answers for section 7: asking for input
KaelinSleevi Jun 12, 2022
44bb4c5
Merge github.com:KaelinSleevi/mod-0-project-be
KaelinSleevi Jun 12, 2022
6d5c5db
add work from exercise 32: loops and arrays
KaelinSleevi Jun 12, 2022
f2b4e0c
add work from exercise 34: accessing elements
KaelinSleevi Jun 12, 2022
e26892f
add work from exercise 39: hashes
KaelinSleevi Jun 12, 2022
3505db1
ruby in 100 minutes: hashes
KaelinSleevi Jun 12, 2022
7464dbd
add arrays practice answers
KaelinSleevi Jun 12, 2022
fc610b9
add work and answers to exercise: hashes2
KaelinSleevi Jun 13, 2022
3814bfb
update relection answers
KaelinSleevi Jun 13, 2022
3dc9b02
Update README.md
KaelinSleevi Jun 14, 2022
4a98841
Update README.md
KaelinSleevi Jun 14, 2022
3a15bd0
Update README.md
KaelinSleevi Jun 14, 2022
e7908bb
Update README.md
KaelinSleevi Jun 14, 2022
031fa1e
Update README.md
KaelinSleevi Jun 15, 2022
569e2bc
Update README.md
KaelinSleevi Jun 15, 2022
3d54f03
Update README.md
KaelinSleevi Jun 15, 2022
fbca80c
update exercise 1 format
KaelinSleevi Jun 18, 2022
6462e94
update exercise 2 format
KaelinSleevi Jun 18, 2022
d2c5af7
update exercise 3 format
KaelinSleevi Jun 18, 2022
1b21178
update exercise 4 format
KaelinSleevi Jun 18, 2022
f247771
update exercise 5 format
KaelinSleevi Jun 18, 2022
76e5165
update exercise 6 format
KaelinSleevi Jun 18, 2022
6710078
update exercise 7 format
KaelinSleevi Jun 18, 2022
65b8e51
Merge github.com:KaelinSleevi/mod-0-project-be
KaelinSleevi Jun 18, 2022
3e558d2
update format for section 2 exercises and drills
KaelinSleevi Jun 18, 2022
f7ad788
update format for section 3 exercises and drills
KaelinSleevi Jun 18, 2022
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
17 changes: 17 additions & 0 deletions section1/ex1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Exercise
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 "This is another line."

Study Drills
1. Make your script print another line.
- I added "puts 'This is another line.'" at the very end.
2. Make your script print only one of the lines.
- I used an octothorpe to in front of each line except one.
3. Put a # (octothorpe) character at the beginning of a line. What did it do? Try to find out what this character does.
- An octothorpe made ruby ignore the code following it.
20 changes: 20 additions & 0 deletions section1/ex2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Exercise
# 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."

Study Drills
1. Find out if you were right about what the # character does and make sure you know what it's called (octothorpe or pound character)
- I was right about the octothorpe. The symbol is used to make note in the code without disturbing it. The symbol tells ruby to ignore it and everything after in that line.
2. Take your ex2.rb file and review each line going backward. Start at the last line, and check each word in reverse against what you should have typed.

3. Did you find more mistakes? Fix them.
- No
4. Read what you typed above out loud, including saying each character by its name. Did you find more mistakes? Fix them.
- No
31 changes: 31 additions & 0 deletions section1/ex3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Exercise
#prints the statement so I know what the code/equation is doing
puts "I will now count my chickens:"
#the amount of hens and roosters(integer) are calculated by the equation below
puts "Hens #{25 + 30 / 6}"
puts "Roosters #{100 - 25 * 3.0 % 4.0}"
#prints a statment to know what the code/equation is now calculating
puts "Now I will count the eggs:"
#this equation calculates the amount of eggs into one integer/amount
puts 3.0 + 2.0 + 1.0 - 5.2 + 4.0 % 2.1 - 1.3 / 4.0 + 6.5
#asking a true or false question based on the equations
puts "Is it true that 3 + 2 < 5 - 7?"
#calculates this question in the equation to tell us if it is true or false
puts 3.0 + 2.0 < 5.2 - 7.3
#both line 16 and 17 are asking ruby to calculate the equations below.
puts "What is 3 + 2? #{3.0 + 2.0}"
puts "What is 5 - 7? #{5.2 - 7.3}"
#this line loops back to the question on line 12. After the equations are calculated it is telling you that your asnwer is why the equation is false
puts "Oh, that's why it's false."
#prints a statement letting us know we are going to do more calculations
puts "How about some more."
#lines 23, 24, 25 are asking if eeach statement is true or false based on the calculations
puts "Is it greater? #{5.2 > -2.0}"
puts "Is it greater or equal? #{5.2 >= -2.0}"
puts "Is it less or equal? #{5.2 <= -2.0}"

Study Drills
1. Above each line, use the # to write a comment to yourself explaining what the line does.
2. Remember in Exercise 0 when you started irb? Start irb this way again and, using the math operators, use Ruby as a calculator.
3. Find something you need to calculate and write a new .rb file that does it.
4. Rewrite ex3.rb to use floating point numbers so it's more accurate. 20.0 is floating point.
55 changes: 55 additions & 0 deletions section1/ex4.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Exercise
# the amount of cars in this scenario is 100
cars = 100
# the amount of space within the car for passengers is 4.0 in a car
space_in_a_car = 4.0
# this means there are 30 drivers available
drivers = 30
# this refers to the amount of passengers there are which happens to be 90
passengers = 90
# this refers to the amount of cars that are not driven. In this case it is the amount of cars minus dirvers which is 60
cars_not_driven = cars - drivers
# this variable represents how many cars will be driven based on the amount of drivers which is 30
cars_driven = drivers
# the carpool_capacity refers to how many people can carpool together which is the cars_driven multiplied by space_in_a_car
carpool_capacity = cars_driven * space_in_a_car
# this refers to the average amount of people that will ride in each car which is passengers divided by cars_driven
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."

Study Drills

```There are 100 cars available.```
```There are only 30 drivers available.```
```There will be 70 empty cars today.```
```ex4.rb:14: undefined local variable or method "carpool_capacity" for
main:Object (NameError)```

1. Explain this error in your own words. Make sure you use line numbers and explain why.
- In my own words I would say that you neglected to give a defined variable or a variable that was a float or integer.
- Say I printed this out but I neglected to define "carpool_capacity". It would look like this:
cars = 100
space_in_a_car = 4.0
drivers = 30
passengers = 90
cars_not_driven = cars - drivers
cars_driven = drivers
carpool_capacity =
average_passengers_per_car = passengers / cars_driven
- The puts "We can transport #{carpool_capacity} people today" would not go through.

2. I used 4.0 for space_in_a_car, but is that necessary? What happens if its just 4?
- 4.0 and 4 are technically the same number, but 4 is an integer and 4.0 is a float. If you just use 4 the output will just be an integer.

3. Remember that 4.0 is a floating point number. It's just a number with a decimal point, and you need 4.0 instead of just 4 so that it is floating point.
3. Write comments above each of the variable assignments.
4. Make sure you know what = is called (equals) and that its purpose is to give data (numbers, strings, etc.) names (cars_driven, passengers).
5. Remember that _ is an underscore character.
6. Try running ruby from the Terminal as a calculator like you did before, and use variable names to do your calculations. Popular variable names are also i, x, and j.
33 changes: 33 additions & 0 deletions section1/ex5.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Exercise
myname = "Kaelin E. Sleevi"
myage = 23 #not a lie in 2009
myheight = 175.26 #centimeters
myweight = 61.29 #kilograms
myeyes = 'Blue/Green/Yellow'
myteeth = 'White'
myhair = 'Red'

puts "Let's talk about #{myname}."
puts "She's #{myheight} inches tall."
puts "She's #{myweight} pounds heavy."
puts "Actually that's not too heavy."
puts "She's got #{myeyes} eyes and #{myhair} hair."
puts "Her teeth are usually #{myteeth} depending on the coffee."

#this line is a little tricky, try to get it exactly right
puts "If I add #{my_age}, #{my_height}, and #{my_weight} I get #{my_age + my_height + my_weight}."

Study Drills
1. Change all the variables so there is no my_ in front of each one. Make sure you change the name everywhere, not just where you used = to set them.

2. Try to write some variables that convert the inches and pounds to centimeters and kilograms. Do not just type in the measurements. Work out the math in Ruby.
irb(main):004:0> 12 * 5
=> 60
irb(main):005:0> 2.54 * 69
=> 175.26
irb(main):006:0>


irb(main):006:0> 135 * 0.454
=> 61.29
irb(main):007:0>
41 changes: 41 additions & 0 deletions section1/ex6.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Exercise
# this assigns the variable "types_of_people" to the number. That way you have 10 types of people for the equation
types_of_people = 10
# this is assigning the variable "x" to a sting that includes the variable types_of_people to print as a statement
x = "There are #{types_of_people} types of people."
# this line assigns the variable binary to "binary"
binary = "binary"
# this variable do_not is being assigned to the string "don't"
do_not = "don't"
# this assigns the variable "y" to a string that includes the variables binary and do_not in the printed statement
y = "Those who know #{binary} and those who #{do_not}."
# the shown variables here in line 13 and 14 are telling you that by putting "puts x/y" it will print the strings assigned to x/y as a statement.
puts x
puts y
# the shown strings in line 16 and 17 tell ruby to print x/y within the strings shown below. Now the terminal will print "I said..."/"I also said..." with the strings x/y within that string.
puts "I said: #{x}."
puts "I also said: '#{y}'."
# this assigns the vaiable of hilarious to false
hilarious = false
# this is a assignment of the joke_evaluation to the string below that also inclues the variable/string assigned above
joke_evaluation = "Isn't that joke so funny?! #{hilarious}"
# this action will print the string assigned to joke_evaluation in the terminal along with the assigned variable of hilarious to be "false"
puts joke_evaluation
# these next two lines show the assignment of the variables w/e to the strings below
w = "This is the left side of..."
e = "a string with a right side."
# this action will print the strings assigned to w and e together. We know that because the two are being added together below. The addition of the two will print in the Terminal
puts w + e

Study Drills
1. Go through this program and write a comment above each line explaining it.

2. Find all the places where a string is put inside a string.
- Lines 5, 16, 17, and 21
3. Are you sure there are only four places? How do you know? Maybe I like lying.
- Yes, the rest of the lines are just assigned to one string (there is not another defined variable within the other assignments) or are the action of puts and the variable assigned.
4. Explain why adding the two strings w and e with + makes a longer string.
- It is adding two defined variables that are defined with strings together into one output.
5. What happens when you change the strings to use ' (single-quote) instead of " (double-quote)? Do they still work? Try to guess why.
- It depends, in some cases here it will make no difference, but in the strings that include an apostrophe the single quotations will open and close the strings in the wrong places. It will not print the same.

27 changes: 27 additions & 0 deletions section1/ex7.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Exercise
print "How old are you? "
age = gets.chomp
print "How tall are you? "
height = gets.chomp
print "How much do you weigh? "
weight = gets.chomp

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

Study Drills
1. Go online and find out what Rubys gets.chomp does.
- I found that the "gets" creates a new line and asks the user to input a integer, variable, float, etc. and gets.chomp does the same thing except that it does not create a new line. gets.chomp allows a user to input as well as "gets", but there will not be a new line that is added after the string.

2. Can you find other ways to use it? Try some of the samples you find.
You can use it ask questions to the user, play a game or run through the game play, you can use it to have users put their own information into the code.

3. Write another "form" like this to ask some other questions.

print "What is your favorite food?"
food = gets.chomp
print "What dessert do you like?"
dessert = gets.chomp
print "What would you like to drink?"
drink = gets.chomp

puts "So, you like #{food}, you would like #{dessert} and want #{drink} for a drink."
3 changes: 3 additions & 0 deletions section1/exercises/booleans.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
p 7 > 2

# YOU DO: print to the terminal the result of "hello" is equal to "Hello":
p "hello" == "Hello"

# YOU DO: print to the terminal the result of 3 is not equal to 4:
p 3 < 4

# YOU DO: print to the terminal the result of 4 is less than or equal to 5:
p 4 <= 5
16 changes: 10 additions & 6 deletions section1/exercises/interpolation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,24 @@
speedy = "quick red fox"
slow_poke = "lazy brown dog"

p # YOUR CODE HERE

# 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}!"

# YOU DO:
# Declare three variables, name/content/data type of your choice. Think carefully
# about what you name the variables. Remember, the goal is to be concise but
# descriptive (it's a hard balance!) Then, print ONE sentence that incorporates
# Declare three variables, name/content/data type of your choice. Think carefully
# about what you name the variables. Remember, the goal is to be concise but
# descriptive (it's a hard balance!) Then, print ONE sentence that incorporates
# all THREE variables.
my_job = "barista"
my_school = "Turing"
my_goal = "Software Engineer"

# YOUR CODE HERE
p "I am currently a #{my_job} full time and I go to #{my_school} so that I can become a #{my_goal}!"
12 changes: 7 additions & 5 deletions section1/exercises/loops.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@

# 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
p "She sells seashells down by the seashore"
end

# Write code that prints the result of 5 + 7 a total of 9 timees
# YOUR CODE HERE
9. times do
p 5 + 7
end
6 changes: 3 additions & 3 deletions section1/exercises/numbers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
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
p 10 % 54
6 changes: 3 additions & 3 deletions section1/exercises/strings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
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..."

# Write out code to print one line from your favorite song or movie.
# YOUR CODE HERE
p "I have everything I need, all of this is within me..."
24 changes: 13 additions & 11 deletions section1/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 section1/exercises/variables.rb`

# Example: Write code that saves your name to a variable and
Expand All @@ -11,31 +11,33 @@
# 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
name = "Harry Potter"
location = "Hogwarts"
p "#{name} must not return to #{location}!"

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

# Write code that subracts 2 from the `students` variable and
# prints the result:
# YOUR CODE HERE
p students
students = 22
leaving_students = 2
p students - leaving_students


# YOU DO:
# Declare three variables, named `first_name`, `is_hungry` and `number_of_pets`.
# Declare three variables, named `first_name`, `is_hungry` and `number_of_pets`.
# Store the appropriate data types in each.
# print all three variables to the terminal.

# IN WORDS:
# How did you decide to use the data type you did for each of the three variables above?
# How did you decide to use the data type you did for each of the three variables above?

# Explain.

Expand All @@ -57,4 +59,4 @@
#-------------------

# Did you run this file in your terminal to make sure everything printed out
# to the terminal as you would expect?
# to the terminal as you would expect?
Loading