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

Andrew Shafer #444

Open
wants to merge 11 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
2 changes: 2 additions & 0 deletions day_1/calculator.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

print (3.5+3)*.65
11 changes: 11 additions & 0 deletions day_1/ex1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#exercise 1: A good First Program

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 "another line"
11 changes: 11 additions & 0 deletions day_1/ex2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#Exercise 2: Comments and Pound Characters

#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."
30 changes: 30 additions & 0 deletions day_1/ex3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
puts "I will now count my chickents:"

#adds 25 to 30 devided by 6
puts "Hens #{25.0 + 30.0 / 6.0}"
#multiplies 24 by 3 devides that number by 4, takes the remeinder and subtracts it from 100
puts "Roosters #{100.0 - 25.0 * 3.0 % 4.0}"

puts "Now I will count the eggs:"

# it takes 4, devides by 2, then it subtracts 1 devided by 4, and then adds 6, 1, 2, 3, and subtrats 5
puts 3.0 + 2.0 + 1.0 - 5.0 +4.0 %2.0 -1.0 /4.0 +6.0

puts "Is it true that 3 +2 < 5 - 7?"

# prints out 3+2, and then 5-7 on a new line
puts 3.0 + 2.0 , 5.0 - 7.0

# prints the answer to the equastion as part of a string
puts "What is 3 + 2? #{3.0+2.0}"
# prints the answer to the equastion as part of a string
puts "What is 5 - 7? #{5.0-7.0}"

puts "Oh, that's why it's false."

puts "How about some more."

#these lines evaluate wheather the left number is, greater than, greater or equal to, less than or equal to the number of the right, respectivly. if it is it prints out true, if not it prints out fallse
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}"
24 changes: 24 additions & 0 deletions day_1/ex4.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#how many cars are there
cars = 100
#how many passangers a car can have
space_in_a_car = 4.0
#number of drivers
drivers = 30
#nubmer of passangers
passengers = 90
#the number of cars that don't get someone to drive them
cars_not_driven = cars - drivers
#number of cars that are driven
cars_driven = drivers
#number of people that can be transported
carpool_capacity = cars_driven * space_in_a_car
#average_passengers_per_car
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."
19 changes: 19 additions & 0 deletions day_1/ex5.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name = 'Zed A. Shaw'
age = 35 # not a lie in 2009
height = 74 #inches
weight = 180 # lbs
eyes = 'Blue'
teeth = 'White'
hair = 'Brown'

height_in_centimeters = height*2.54
weight_in_kilograms = weight*0.453592

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 #{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}."
34 changes: 34 additions & 0 deletions day_1/ex6.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Strings and Text
#this is a number
types_of_people = 10
#this puts that nuber in a stinrg
x = "There are #{types_of_people} types of people."
#string
binary = "binary"
#string
do_not = "don't"
#string with string in it
y = "Those who know #{binary} and those who #{do_not}."

#printing strings
puts x
puts y

#printing strings in more strings
puts "I said:#{x}."
puts "I also said: '#{y}'"

#bollion
hilarious = false
#bollion in string
joke_evaluation = "Isn't that joke so funny?! #{hilarious}"

#printing bollion in string
puts joke_evaluation

#strings
w = "This is the left side of..."
e = "a string with a right side."

#combining strings
puts w + e
10 changes: 10 additions & 0 deletions day_1/ex7.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#excercise 11: asking Questions

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."
3 changes: 2 additions & 1 deletion day_1/exercises/interpolation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
speedy = "quick red fox"
slow_poke = "lazy brown dog"

p # YOUR CODE HERE
p "The #{speedy} jumps over #{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
"In a predictable result, the #{slow_poke} beat the #{speedy}!"
8 changes: 6 additions & 2 deletions day_1/exercises/loops.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@

# Example: Write code that prints your name five times:
5.times do
p "Hermione Granger"
puts "Andrew Shafer"
end

# Write code that prints the sum of 2 plus 2 seven times:
7.times do
# YOUR CODE HERE
puts 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
7 changes: 4 additions & 3 deletions day_1/exercises/numbers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
p 2 + 2

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

# 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
6 changes: 4 additions & 2 deletions day_1/exercises/strings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
# `ruby day_1/exercises/strings.rb`

# Example: Write code that prints your name to the terminal:
p "Alan Turing"
p "Andrew Shafer"

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

# 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..."
11 changes: 9 additions & 2 deletions day_1/exercises/variables.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
# 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
# prints what that variable holds to the terminal:
name = "Harry Potter"
name = "Andrew Shafer"
p name

# 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

string = "Harry Potter must not return to Hogwarts!"
p string

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

p students

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

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

`print "Hello World!"`

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

'#'

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

a float is a number with a decimal while an integer is a number without a descimal.

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`.

interpolation is basically something that lest you run code inside of a string.

'puts "the animal is a #{animal}"'


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

gets.chomp


1. Name and describe two common string methods:


'.length'
this method tells us how long the string is.


'.upcase'
this method changes the string to be all uppercase.
11 changes: 11 additions & 0 deletions day_2/aray_methods.ms
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


.sort : returns a sorted array
.each : cycles through an array
.join : take a array and puts each element of that array into a string
.index : returns the index position of the
include? : if an array contains a specific element then it returns true, if not, then it returns false
.collect : goes through each element in an array and modifies it
.first : returns the first element of the array
.last : returns the last element of the array
.shuffle : returns an array that is NOT sorted.
18 changes: 17 additions & 1 deletion day_2/exercises/arrays.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@

# Write code that stores an array of states in a variable,
# then prints that array:
states = #YOUR CODE HERE
states = ["CO", "NY", "CA", "TX", "AZ"] #YOUR CODE HERE
p states

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


# Example: Write code that prints the number of elements
# in your above array of animals:
Expand All @@ -24,17 +27,30 @@
# 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[0]



# Write code that prints the last item of your foods array:
# YOUR CODE HERE
p foods[-1]



# Write code that adds "lion" to your animals array
# and prints the result (Hint- use a method):
# YOUR CODE HERE
animals.push("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.pop()
p foods
20 changes: 16 additions & 4 deletions day_2/exercises/iteration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,26 @@
# "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

# Write code that stores an array of numbers in a variable,
# then iterates over that array to print doubles of each number:
foods = ["egg", "toco", "hotdog"]

foods.each do |food|
p "add #{food} to the 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

numbers = [1, 2, 3, 4, 57, 8, 95, 0, 3, 6]

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