Skip to content

Commit

Permalink
Cleaning up, fixing typos
Browse files Browse the repository at this point in the history
  • Loading branch information
citizen428 committed May 3, 2010
1 parent ac2ffa5 commit d77e5d7
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions coreruby/exercise_set1/e0104ageinseconds.rb
Expand Up @@ -3,8 +3,8 @@
Displays the age (in years) of a person who is 979000000 seconds old.
There are 31536000 seconds in a non leap year
=end
AgeInSeconds = 979000000
SecondsPerYear = 60 * 60 * 24 * 365
age_in_years = AgeInSeconds / SecondsPerYear.to_f
AGE_IN_SECONDS = 979_000_000
SECONDS_PER_YEAR = 60.0 * 60 * 24 * 365
age_in_years = AGE_IN_SECONDS / SECONDS_PER_YEAR

puts "979000000 seconds are #{"%.2f" % age_in_years} years."
puts "979000000 seconds are %.2f years." % age_in_years
4 changes: 1 addition & 3 deletions coreruby/exercise_set1/e0105minutesinayear.rb
Expand Up @@ -3,7 +3,5 @@
Calculates the minutes in a year
60 minutes/hour - 24 hours/day - 365 days/year
=end
MinutesInYear = 60 * 24 * 365

puts "There are #{MinutesInYear} minutes in a year"
puts "There are #{60 * 24 * 365} minutes in a year"

4 changes: 2 additions & 2 deletions coreruby/exercise_set2/e0202convert.rb
@@ -1,7 +1,7 @@
=begin
Function to convert temperatures from Fahreheit to Celsius.
Function to convert temperatures from Fahrenheit to Celsius.
Dies if temp_in_fahrenheit is not a number.
=end
def convert(temp_in_fahrenheit)
(temp_in_fahrenheit - 32) * 5 / 9
(temp_in_fahrenheit - 32) / 1.8
end
6 changes: 3 additions & 3 deletions coreruby/exercise_set2/e0204ftoc.rb
Expand Up @@ -6,13 +6,13 @@
=end

def convert(temp_in_fahrenheit)
(temp_in_fahrenheit - 32) * 5 / 9
(temp_in_fahrenheit - 32) / 1.8
end

print 'Please enter temperature in Fahrenheit: '
STDOUT.flush
temp_to_convert = gets.to_f
puts "#{temp_to_convert} degress Fahrenheit are #{"%.2f" % convert(temp_to_convert)} degrees Celsius."
input_temp = gets.to_f
puts "%.2fF = %.2fC." % [input_temp, convert(input_temp)]



13 changes: 3 additions & 10 deletions coreruby/exercise_set3/e0301splitstring.rb
Expand Up @@ -2,20 +2,13 @@
=begin
Breaks a multiline string up into individual lines
and outputs them including line numbers.
=end

s="Welcome to the forum.\nHere you can learn Ruby.\nAlong with other members.\n"
s.split.each_with_index do |line, line_count|
puts "Line #{line_count + 1}: #{line}"
end

=begin
Ruby 1.9:
s.each_line.with_index { |l, i| puts "Line #{i+1}: #{l}"}
Needs Ruby 1.9
=end

s="Welcome to the forum.\nHere you can learn Ruby.\nAlong with other members.\n"

s.each_line.with_index { |line, i| puts "Line #{i+1}: #{line}" }



Expand Down
6 changes: 3 additions & 3 deletions coreruby/exercise_set3/e0303leapyearcheck.rb
Expand Up @@ -4,12 +4,12 @@
=end

def leap_year?(year)
(( year % 4 == 0 ) && (year % 100 != 0 )) || year % 400 == 0
(year % 4 == 0 && year % 100 != 0 ) || year % 400 == 0
end

print 'Please enter the year to be checked: '
STDOUT.flush
year_to_check = gets.to_i
input_year = gets.to_i

puts "%s:#{' not' unless leap_year?(year_to_check)} a leap year" % year_to_check
puts "#{input_year}:#{' not' unless leap_year?(input_year)} a leap year"

11 changes: 10 additions & 1 deletion coreruby/exercise_set3/e0304minutesperyear.rb
@@ -1,7 +1,16 @@
#!/usr/bin/ruby
=begin
Write a method leap_year?. It should accept a year value from the user,
check whether it's a leap year, and then return true or false.
With the help of this method calculate and display the number of minutes
in a leap year or non-leap year.
Note: a century year is a leap year only if it is divisible by 4.
=end

def leap_year?(year)
(( year % 4 == 0 ) && (year % 100 != 0 )) || year % 400 == 0
(year % 4 == 0 && year % 100 != 0) || year % 400 == 0
end

print 'Please enter a year: '
Expand Down

0 comments on commit d77e5d7

Please sign in to comment.