-
Notifications
You must be signed in to change notification settings - Fork 41
asignment sumitted #31
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 |
|---|---|---|
|
|
@@ -2,31 +2,43 @@ | |
| # -------------------------------------------------------------------------- | ||
|
|
||
| # 1. Write a method to swap two variables. | ||
| # def method(a, b) | ||
| # Your code here.... | ||
| # end | ||
| def swap(a,b) | ||
| a=a+b | ||
| b=a-b | ||
| a=a-b | ||
| puts "a=#{a} b=#{b}" | ||
| end | ||
| => swap(20,50) | ||
|
|
||
| [50,20] | ||
|
|
||
|
|
||
| # 2. Write any one use case of === operator. | ||
| # Your answer here... | ||
|
|
||
| # 2. Write any one use case of === aperator | ||
| (1..9) === 5.16732 returns true | ||
|
Collaborator
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. Write here in text |
||
|
|
||
|
|
||
| # 3. Print array of alphabates using Range operator. | ||
| # Your answer here... | ||
|
|
||
|
|
||
|
|
||
| # 4. Print 'Ho! Ho! Ho! Merry Christmas!' using string interpolation and * operator. | ||
| # Your answer here... | ||
| ('a'..'m').to_a returns all alphabets starting from A to M. | ||
|
|
||
| ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m"] | ||
|
|
||
| # 4. Print 'Ho! Ho! Ho! Merry Christmas!' using string interpolation and * operato | ||
| a = 'Ho!' * 3 | ||
| b = 'Merry christmas!' | ||
| puts a+b | ||
| Ho!Ho!Ho!Merry Cristmas! | ||
|
Collaborator
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. 👍 |
||
|
|
||
| # 5. Write a ruby program that perform following operations: | ||
|
Collaborator
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. Write as: |
||
| # a. Ask user his/her name | ||
| # b. Ask user his/her age | ||
| # c. Finally, print result in the form | ||
| # "Your name is <user's name>" | ||
| # "Your age is <user's age>" | ||
| # Your answer here... | ||
| @name = gets | ||
| @age = gets | ||
|
|
||
| puts "Your name is #{@name}" | ||
| puts "your name is #{@age}" | ||
| Your name is Pankaj | ||
| Your age is 25 | ||
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.
Don't write puts in method. It should only return me swapped values.