-
Notifications
You must be signed in to change notification settings - Fork 41
Assignments #36
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?
Assignments #36
Changes from all commits
b29059b
15a7b79
71f8de3
c4fff40
80ff9c1
2cdec85
9c1dcf7
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 |
|---|---|---|
| @@ -1,25 +1,41 @@ | ||
| # Day 1 : Assignments | ||
| # -------------------------------------------------------------------------- | ||
|
|
||
| # 1. Write a method to swap two variables. | ||
| def method(a, b) | ||
| my_cde | ||
| <<<<<<< HEAD | ||
| # 1. Write a method to swap two variables. | ||
| def swap_num(a,b) | ||
| a = a + b | ||
| b = a - b | ||
| a = a - b | ||
| return a, b | ||
| end | ||
| swap_num(10,20) | ||
|
|
||
|
|
||
| ======= | ||
| # 1. Write a method to swap two variables. | ||
| def swap_it(a, b) | ||
| return b, a | ||
| end | ||
| swap_it(10,20) | ||
| >>>>>>> upstream/master | ||
|
|
||
|
|
||
| # 2. Write any one use case of === operator. | ||
| # Your answer here... | ||
|
|
||
| def equals?(a, b) | ||
| a === b | ||
| end | ||
| equals?(1, "one") | ||
|
|
||
|
|
||
| # 3. Print array of alphabates using Range operator. | ||
| # Your answer here... | ||
|
|
||
| ('a'..'h').to_a | ||
| => ["a","b","c","d","e","f","g","h"] | ||
|
|
||
|
|
||
| # 4. Print 'Ho! Ho! Ho! Merry Christmas!' using string interpolation and * operator. | ||
| # Your answer here... | ||
| "#{'Ho! '*3}Merry Christmas!" | ||
| =>Ho! Ho! Ho! Merry Christmas! | ||
|
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. Instead of + operator please use string interpolation. |
||
|
|
||
|
|
||
|
|
||
|
|
@@ -29,4 +45,13 @@ def method(a, b) | |
| # c. Finally, print result in the form | ||
| # "Your name is <user's name>" | ||
| # "Your age is <user's age>" | ||
| # Your answer here... | ||
| def demo_func() | ||
| puts "Enter Your Name" | ||
| name = gets.chomp | ||
| puts "Enter Your Age" | ||
| age = gets.chomp | ||
| puts "hey #{name} of age #{age}" | ||
| end | ||
| demo_func() | ||
| => Hey Rakesh of age 28 | ||
|
|
||
|
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. @anupk18 , Added some comments for the Day-1 Assignment. |
||
| 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.
Please resolve the merge conflicts.