Skip to content
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
27 changes: 20 additions & 7 deletions Day1/assignment.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
# Day 1 : Assignments
# --------------------------------------------------------------------------

# 1. Write a method to swap two variables.
# def method(a, b)
# Your code here....
# end

# 1. Write a method to swap two variables.
def swap(a, b)
a += b
b = a - b
a -= b
puts "a = #{a} b = #{b}"
end
swap(3, 5)


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


It can used to check equality.
EG: (1...10)==3 returns true

# 3. Print array of alphabates using Range operator.
# Your answer here...

alphabets=Array('a'..'z')


# 4. Print 'Ho! Ho! Ho! Merry Christmas!' using string interpolation and * operator.
# Your answer here...
str = 'Ho! ' * 3
print "#{str} Merry Christmas!"



Expand All @@ -30,3 +36,10 @@
# "Your name is <user's name>"
# "Your age is <user's age>"
# Your answer here...
print 'Enter your name: '
name = gets
print 'Enter your age: '
age = gets
puts "Your name is #{name}"
puts "Your age is #{age}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Create one file like test.rb and paste following lines:

puts "Enter your name"
name= gets
puts "Enter  your age"
age=gets
puts "Your name is #{name}"
puts "Your age is #{age}"

Then from command line execute as:

$> ruby test.rb 

then see how the code behaves. Note there will be extra line during entering your name and age and also printing.
You need to resolve those issues