-
Couldn't load subscription status.
- Fork 74
Tasks are done #4
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| def add_up(i) | ||
| if (i.class !=Integer) || (i <1) | ||
| puts "Please enter a positive integer" | ||
| else | ||
| sum = 0 | ||
| loop do | ||
| sum += i | ||
| i -= 1 | ||
| if i == 0 | ||
| break | ||
| end | ||
| end | ||
| puts sum | ||
| end | ||
| end | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation is a bit off |
||
| add_up(6) | ||
| add_up(-8) | ||
| add_up(5) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| def Ask(question) | ||
| puts question | ||
| string = gets.chomp + " " | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rather than adding a space to the end of the word here I would probably wait till the end of the method and just use |
||
| return string | ||
| end | ||
|
|
||
|
|
||
|
|
||
|
|
||
| full_name.push(Ask("Enter your first name, please")) | ||
| full_name.push(Ask("Enter your middle name, please")) | ||
| full_name.push(Ask("Enter your last name please")) | ||
|
|
||
| puts "Hello " + full_name[0] + full_name[1] + full_name[2] + "!" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorta same as the above, I would use |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| def is_leap(year) | ||
| if year %400 == 0 | ||
| return true | ||
| elsif year % 100 == 0 | ||
| return false | ||
| elsif year % 4 == 0 | ||
| return true | ||
| else | ||
| return false | ||
|
|
||
| end | ||
| end | ||
|
|
||
| year = begin_year | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure what this line is doing. |
||
| while year <= end_year do | ||
|
|
||
| if is_leap(year) | ||
| puts year | ||
| end | ||
| year +=1 | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| words = [] | ||
|
|
||
| while true do | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I try to avoid using |
||
| puts "Please enter a word. Type Enter to quit" | ||
| word = gets.chomp | ||
| if word == '' | ||
| break | ||
| elsif word.index(/[^A-Za-z]/) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good validation! |
||
| puts "Not a word. Please try again" | ||
| else | ||
| words.push(word) | ||
| end | ||
| end | ||
| words = words.sort | ||
| words.each {|word| puts word} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice validation!