-
Notifications
You must be signed in to change notification settings - Fork 41
Completed assignment Day1 #33
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,24 +2,26 @@ | |
| # -------------------------------------------------------------------------- | ||
|
|
||
| # 1. Write a method to swap two variables. | ||
| # def method(a, b) | ||
| # Your code here.... | ||
| # end | ||
| def swap(a,b) | ||
| a,b = b,a | ||
| end | ||
|
|
||
|
|
||
|
|
||
| # 2. Write any one use case of === operator. | ||
| # Your answer here... | ||
| Used to test equality within a when clause of a case statement. | ||
| ex: (1...10) === 5 | ||
| => it returns true. | ||
|
|
||
|
|
||
|
|
||
| # 3. Print array of alphabates using Range operator. | ||
| # Your answer here... | ||
| puts ('a'..'z').to_a | ||
|
|
||
|
|
||
|
|
||
| # 4. Print 'Ho! Ho! Ho! Merry Christmas!' using string interpolation and * operator. | ||
| # Your answer here... | ||
| print "Ho! "*3 + "Merry Christmas!" | ||
|
|
||
|
|
||
|
|
||
|
|
@@ -30,3 +32,9 @@ | |
| # "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 | ||
| print "Your Name is : " + name + "Your Age is : " + age | ||
|
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. Try to create another ruby file like test.rb and copy paste this code and check how it works. What is your name: <your name here>
What is your age : <your age>
Your name is <your name>.
Your name is <your age>.
Author
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. Hi @budhrg Thank you for comments; I've tried above code using .rb file and execute the same from command prompt. E:\RubyProg>ruby r1.rb |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,33 @@ | ||
| # Question1 | ||
| # Get the first letter from the string "Hello, Ruby!!". | ||
| str[0] | ||
| => "H" | ||
|
|
||
| # Question2 | ||
| # Get the first through 5th elements from the "Hello, Ruby!!" string. | ||
| str[4] | ||
| =>"0" | ||
|
|
||
| # Question3 | ||
| # Check the 'sprintf' documentation and the % documentation in the String class | ||
| # and write one line code to print exact following line | ||
| # "1$ = Rs60.48" | ||
| sprintf("1$ = Rs %#.2f",60.48) | ||
| => "1$ = Rs 60.48" | ||
|
|
||
|
|
||
| # Question4 | ||
| # What is the problem with the following code? Correct it and puts. | ||
| # my variable = 'Mr. White' | ||
| my_variable='Mr. White' | ||
| puts my_variable | ||
| =>Mr. White | ||
|
|
||
|
|
||
|
|
||
| # Question5 | ||
| # Print the result - Concatenate the following strings | ||
| first = 'Beautiful ' | ||
| second = 'face tattoo' | ||
| second = 'face tattoo' | ||
| puts first+second | ||
| => Beautiful face Tattoo |
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.
👍 That is the expected code. Good