Skip to content
Open

Done #34

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
39 changes: 32 additions & 7 deletions Day1/assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,35 @@
# --------------------------------------------------------------------------

# 1. Write a method to swap two variables.
# def method(a, b)
# Your code here....
# def swap(a,b)
# c=a
# a=b
# b=c
# puts "A:#{a} B:#{b}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Method should not print anything. It should only perform task.

# end

swap(10,20)


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

if((1..5)===3)
puts "\n\n 3 is range of 1 to 5"
end
if((1..5)===7)
puts "7 is range of 1 to 5"
else
puts "\n\n 7 is not range of 1 to 5 \n\n"
end



# 3. Print array of alphabates using Range operator.
# Your answer here...
('a'..'z').to_a



# 4. Print 'Ho! Ho! Ho! Merry Christmas!' using string interpolation and * operator.
# Your answer here...
puts 'Ho!'*3+"Merry Christmas!"



Expand All @@ -29,4 +40,18 @@
# c. Finally, print result in the form
# "Your name is <user's name>"
# "Your age is <user's age>"
# Your answer here...

def user()
puts "enter the name"
name=gets
puts "enter the age"
age=gets
puts "hello#{name} your age is #{age}"
end
user()

Copy link
Collaborator

Choose a reason for hiding this comment

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

Try to create another ruby file like test.rb and copy paste this code and check how it works.
It should be print:

What is your name: <your name here>
What is your age   : <your age>

Your name is <your name>.
Your name is <your age>.