User Input and Output
Capture user input from the console and format output using puts and gets.
User Input and Output is a free Ruby Academy lesson on CoddyKit — lesson 2 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Ruby Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.
1
User Input and Output
Interacting with users through input and output is an essential part of many applications.
In this lesson, you will learn how to capture user input and format output using puts and gets.

2
Displaying Output with puts
Use puts to print text to the console.
puts 'Hello, Ruby!'3
Using print
print works like puts but does not add a new line.
print 'Hello, '
print 'Ruby!'4
Getting User Input
Use gets to capture user input from the console.
puts 'Enter your name:'
name = gets
puts "Hello, #{name}"5
Using gets.chomp
gets captures the newline character. Use chomp to remove it.
puts 'Enter your city:'
city = gets.chomp
puts "You live in #{city}."6
Interpolating Variables in Strings
Use #{} inside double quotes to insert variables into a string.
name = 'Alice'
puts "Hello, #{name}!"7
Getting Numeric Input
Use to_i to convert input into an integer.
puts 'Enter your age:'
age = gets.chomp.to_i
puts "In 5 years, you will be #{age + 5} years old."8
9
Formatting Output
Use printf or sprintf to format output.
price = 9.99
printf('Price: $%.2f', price)10
Congratulations!
You have learned how to capture user input and format output in Ruby.
Next, you will explore working with JSON and YAML.

Frequently asked questions
Is the “User Input and Output” lesson free?
Yes — the full text of “User Input and Output” is free to read here on the web, and the Ruby Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Ruby Academy course, upgrade to CoddyKit PRO.
What will I learn in “User Input and Output”?
Capture user input from the console and format output using puts and gets. You practise Ruby Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Ruby Academy?
No prior experience is required. Ruby Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 3, so you can start here or from the beginning and move at your own pace.
How long does the “User Input and Output” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Ruby Academy lesson?
Yes. Every Ruby Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Reading and Writing Files
- User Input and Output
- Working with JSON and YAML