-
Notifications
You must be signed in to change notification settings - Fork 42
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
Assignment 1 submitted #30
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,25 +2,41 @@ | |
# -------------------------------------------------------------------------- | ||
|
||
# 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(10,20) | ||
|
||
|
||
# 2. Write any one use case of === operator. | ||
# Your answer here... | ||
|
||
(1..10)===10.00 | ||
=> true | ||
|
||
(1..10)===10.01 | ||
=> false | ||
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. What does it mean? |
||
|
||
|
||
# 3. Print array of alphabates using Range operator. | ||
# Your answer here... | ||
# 3. Print array of alphabate using Range operator. | ||
('a'..'z').to_a | ||
["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", | ||
"p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "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. 👍 |
||
|
||
|
||
# 4. Print 'Ho! Ho! Ho! Merry Christmas!' using string interpolation and * operator. | ||
# Your answer here... | ||
|
||
a='Ho! '*3 | ||
"Ho! Ho! Ho! " | ||
b='Merry Christmas' | ||
"Merry Christmas" | ||
a+b | ||
"Ho! Ho! Ho! Merry Christmas" | ||
puts a+b | ||
Ho! Ho! Ho! Merry Christmas | ||
|
||
|
||
# 5. Write a ruby program that perform following operations: | ||
|
@@ -29,4 +45,23 @@ | |
# c. Finally, print result in the form | ||
# "Your name is <user's name>" | ||
# "Your age is <user's age>" | ||
# Your answer here... | ||
|
||
Ans | ||
def personinfo() | ||
a="What is your name" | ||
puts a | ||
name=gets.chomp | ||
b="What is your age?" | ||
puts b | ||
age=gets | ||
puts "Your name is "+name+" and your age is "+age | ||
end | ||
/*output*/ | ||
What is your name | ||
Raj | ||
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. Name should be entered in the same line where "What is your name" is shown. |
||
What is your age | ||
25 | ||
Your name is Raj and 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 or any print statement in method.
Swap method should only perform operation