1. Writing and Running Ruby Programs
Activity 1.01: Generating Email Addresses Using Ruby
Solution
- Define and print the first name variable:
puts "Enter your first name: "
- Use the
gets.chomp
method to allow the user input to be stored in the variables:first_name = gets.chomp
- Similarly, create a new variable for the last name of the user and print it. Also apply
gets.chomp
on the variable to store the input data:puts "Enter your last name: " last_name = gets.chomp
- Lastly, use string interpolation to combine the first and last name with the domain name to generate the email address:
puts "#{first_name}#{last_name}@rubyprogram.com" #Output : Enter your first name: akshat Enter your last name: paul =>[email protected]
Expected output:
Activity 1.02: Calculating the Area and Perimeter for a Candy Manufacturing Plant
Solution
- Enter the IRB shell and print the...