Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
55 changes: 45 additions & 10 deletions Day1/assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

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


swap(10,20)


# 2. Write any one use case of === operator.
# Your answer here...

(1..10)===10.00
=> true

(1..10)===10.01
=> false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does it mean?
You need to give answer in text.



# 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"]

Copy link
Collaborator

Choose a reason for hiding this comment

The 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:
Expand All @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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