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

Alex Ferencz #443

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions day_1/ex1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"Hellow World!"
"Hello Again"
"I like typing this."
"This is fun."
"Yay! Printing."
"I'd much rather you 'not'."
# puts 'I "said" do not touch this.'
puts 'I wrote 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."
3 changes: 3 additions & 0 deletions day_1/ex3.1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
puts "This file is going to help me figure out my bills"
x = 710+210+80+80
puts "#{x} isn't event that much"
24 changes: 24 additions & 0 deletions day_1/ex3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
puts "I will now count my chickens:"
puts "Hens #{25.0 + 30.0 / 6.0}"
#the curly brackets do the math in the string
puts "Roosters #{100.0 - 25.0 * 3.0 % 4.0}"
#the curly brackets do the math in the string
puts "Now I will count the eggs:"
puts 3.0+20+1.0-5.0+4.0%2.0-1.0/4.0+6.0
# no need for curly brackets because it is not in the string and the equation is alone on a line
puts "Is it true that 3 + 2 < 5 - 7?"
#the question is asked
puts 3+2<5-7
# the equation is given and solved. It has been determined to be false
puts "What is 3 + 2? #{3 + 2}"
# the question is asked and the actual work is done in the same spot in the curly brackets
puts "What is 5 - 7 #{5-7}"
# the question is asked and the actual work is done in the same spot in the curly brackets
puts "Oh, that's why it's false."
puts "How about some more."

puts "Is it greater? #{5 > -2}"
# the question is asked and the actual work is done in the same spot in the curly brackets
puts "Is it greater or equal? #{5 >= -2}"
# the question is asked and the actual work is done in the same spot in the curly brackets
puts "Is it less or equal? #{5 <= -2}"
17 changes: 17 additions & 0 deletions day_1/ex4.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cars = 100
space_in_a_car = 4.0
drivers = 30
passengers = 90
cars_not_driven = cars - drivers
cars_driven = drivers
carpool_capacity = cars_driven * space_in_a_car
average_passengers_per_car = passengers / cars_driven

puts "There are #{cars} cars available."
puts "There are only #{drivers} drivers available."
puts "There are only #{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."

# When I deleted line 7 and ran it, the same error code popped up. Zed must have forgotten to define what carpool capcity was.
22 changes: 22 additions & 0 deletions day_1/ex5.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name = 'Zed A. Shaw'
age = 35 # not a lie in 2009
height =74 # inches
height_in_centimeters = height * 2.54
weight = 180 # lbs
weight_in_kilos = height * 0.453592
eyes = 'Blue'
teeth = 'White'
hair = "Brown"

puts "Let's talk about #{name}"
puts "He's #{height} tall."
puts "That means #{height_in_centimeters} in centimeters."
puts "He's #{weight} pounds heavy."
puts "Acutally that's not too heavy."
puts "Especially in kilos like this #{weight_in_kilos}"
puts "He's got #{eyes} and #{hair} hair."
puts "His teeth are usually #{teeth} depending on the coffee."


#this line is tricky, try to get it exactly right
puts "If I add #{age}, #{height}, and #{weight} I get #{age + height + weight}."
33 changes: 33 additions & 0 deletions day_1/ex6.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# defining types of people as 10
types_of_people = 10
# defining x as the string
x = "There are #{types_of_people} types of people."
# defining binary
binary = "binary"
# defining do not as don't
do_not = "don't"
#defining y as the string
y = "Those who know #{binary} and those who #{do_not}."
# these two are telling ruby to export x and y values
puts x
puts y

# these two are asking for the two strings to be written including the values which are other strings
puts "I said: #{x}."
puts "I also said:'#{y}'."

# this defines hilarious
hilarious = false

# this defines joke_evaluation which includes the previously defined variable
joke_evaluation = "Ins't that joke so funny?! #{hilarious}"

# this is asking ruby to export joke_evaluation
puts joke_evaluation

# these two are defining variables w and each
w = 'This is the left side of...'
e = 'a string with a right side.'

# this is asking ruby to export w and e values next to eachother
puts w + e
17 changes: 17 additions & 0 deletions day_1/ex7.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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, youre #{age} old, #{height} tall and #{weight} heavy."

#chomp stops the line break/new line from being created after the gets adds the answer gotten to the strings

print "What is your favorite animal?"
animal = gets.chomp
print "What would happen if you never saw that animal again?"
reaction = gets.chomp

puts "So #{animal} is really important to you. I'd probably #{reaction} too."
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}!"
6 changes: 4 additions & 2 deletions day_1/exercises/loops.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@

# 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
6 changes: 3 additions & 3 deletions day_1/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 54 % 10
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.... we both know you mean soda...."
16 changes: 9 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,21 @@
# 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
warning_message = "Harry Potter must not return to Hogwarts!"
p warning_message

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

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

p students2
15 changes: 9 additions & 6 deletions day_1/questions.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
## Day 1 Questions

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?

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

Integers are whole numbers and float have a decimal place
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`.

"What a cute #{animal} you have over there!"
1. What method is used to get input from a user?

gets
1. Name and describe two common string methods:
.length finds out how many characters there are in a strings
.chomp stops the line break from occurring after input from user.
1 change: 1 addition & 0 deletions day_2/array_methods.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
each method: each allows us to do the same thing to each part/element of an array. For example if we had a bunch of elements in an array and we wanted to loop back over and over and do the same thing to each individual element we would use each.
18 changes: 10 additions & 8 deletions day_2/exercises/arrays.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,33 @@

# Write code that stores an array of states in a variable,
# then prints that array:
states = #YOUR CODE HERE
states = ["Alabama", "Arkanas", "Alaska"]
p states

# Write code that stores an array of foods in a variable,
# then prints that array:
# YOUR CODE HERE
foods = ["Salami", "Pepperoni", "Bratwurst"]
p foods

# Example: Write code that prints the number of elements
# in your above array of animals:
p animals.count

# Write code that prints the number of elements
# in your above array of foods:
# YOUR CODE HERE
p foods.count

# Write code that prints "Zebra" from your animals array:
# YOUR CODE HERE
p animals.first

# Write code that prints the last item of your foods array:
# YOUR CODE HERE
p foods.last

# Write code that adds "lion" to your animals array
# and prints the result (Hint- use a method):
# YOUR CODE HERE

animals.append("lion")
p animals
# Write code that removes the last element from your foods array
# and prints the result (Hint- use a method):
# YOUR CODE HERE
foods.delete ("Bratwurst")
p foods
20 changes: 14 additions & 6 deletions day_2/exercises/iteration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@
# "The <animal> is awesome!" for each animal:

animals.each do |animal|
# YOUR CODE HERE
p "The #{animal} is awesome!"
end

# Write code that stores an array of foods in a variable,
# Write code that stores an array of foods in a variable,
# then iterates over that array to print
# "Add <food> to shopping list" for each food item:
# YOUR CODE HERE
foods = ["bok choy", "soy", "tomato", "banana"]
foods.each do |food|
p "Add #{food} to shopping list"
end

# Write code that stores an array of numbers in a variable,
# then iterates over that array to print doubles of each number:
# YOUR CODE HERE
# Write code that stores an array of numbers in a variable,
# then iterates over that array to print doubles of each number:
numbers = [5,6,7,8,9]
numbers.each do |number|
2.times do
p number
end
end
69 changes: 69 additions & 0 deletions day_2/experiment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
numbers = [1,2,3,4]

numbers.each do |number|
2.times do
p number
end
end

numbers.each do |number|
3.times do
p number
end
end

numbers.each do |number|
p number * 2
end

numbers.each do |number|
p number * 3
end

numbers.each do |number|
if number.even?
p number
end
end

numbers.each do |number|
if number.odd?
p number
end
end

names = ["Alice Smith", "Bob Evans", "Roy Rogers"]

names.each do |name|
p name
end

names.each do |name|
p name.split.first
end

names.each do |name|
p name.chr
end

names.each do |name|
last_name = name.split.last
p "#{last_name} #{last_name.length}"
end

total_number_of_letters = 0
names.each do |name|
total_number_of_letters += name.length
end
p total_number_of_letters
#Given an array of first and last names, e.g. , how would you print out the full names line by line?
#How would you print out only the first name?
#How would you print out only the last name?
#How could you print out only the initials?
#How can you print out the last name and how many characters are in it?
#How can you create an integer which represents the total number of characters in all the names?


animals = ["zebra", "giraffe", "elephant"]

p animals[1]
Loading