Skip to content
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
15 changes: 15 additions & 0 deletions add_up.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#Write a program with a function add_up(i) .
def add_up(i)
sum = 0
for num in 1..i
sum += num
end
return sum
end
result1 = add_up(6)
result2 = add_up(10)
result3 = add_up(15)

puts "the sum of 1 to 6 = #{result1}"
puts "the sum of 1 to 10 = #{result2}"
puts "the sum of 1 to 15 = #{result3}"
19 changes: 19 additions & 0 deletions full_name.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

contact_list = []
def ask (question, kind = "string")
print question + ""
answer = gets.chomp
answer = answer.to_i if kind == "number"
return answer
end

answer = ask ("what is your first name?")
contact_list << answer
answer = ask ("waht is your middle name?")
contact_list << answer
answer = ask ("what is your last name")
contact_list << answer
puts "Hello, #{contact_list.join('')}!"

contact_list = []

16 changes: 16 additions & 0 deletions leap_year.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def is_leap_year(year)
(year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)
end

print "Enter starting year: "
start_year = gets.chomp.to_i

print "Enter ending year: "
end_year = gets.chomp.to_i

puts "Leap years between #{start_year} and #{end_year}:"

(start_year..end_year).each do |year|
puts year if is_leap_year(year)
end

22 changes: 22 additions & 0 deletions sorted_out.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#1 prompt user
#2 gather input (string)
#3 loop until blank word
#4 sort array
#5 print array

array = []
input = "a"

until input.empty?
puts "Add a word:"
input = gets.chomp
array << input unless input.empty?
end

sorted_array = array.sort

puts "Sorted words:"
sorted_array.each do |word|
puts word
end