0
0
Rubyprogramming~15 mins

Puts, print, and p output differences in Ruby - Mini Project: Build & Apply

Choose your learning style9 modes available
Puts, print, and p output differences
📖 Scenario: Imagine you are writing a simple Ruby program to show different ways to display text and data on the screen. You want to learn how puts, print, and p behave differently when showing output.
🎯 Goal: You will create a Ruby program that uses puts, print, and p to display the same string and number. This will help you see how each method shows output differently.
📋 What You'll Learn
Create a string variable called message with the value "Hello, Ruby!"
Create a number variable called number with the value 42
Use puts to display the message variable
Use print to display the message variable
Use p to display the message variable
Use puts, print, and p to display the number variable
💡 Why This Matters
🌍 Real World
Knowing how to display information clearly helps when writing programs that show messages or debug data.
💼 Career
Understanding output methods is important for debugging and user interaction in Ruby programming jobs.
Progress0 / 4 steps
1
Create variables for message and number
Create a string variable called message with the value "Hello, Ruby!" and a number variable called number with the value 42.
Ruby
Need a hint?

Use = to assign values to variables. Strings go inside double quotes.

2
Use puts to display the message
Use puts to display the variable message.
Ruby
Need a hint?

puts adds a new line after printing.

3
Use print and p to display the message
Use print and p to display the variable message. Write one line with print message and one line with p message.
Ruby
Need a hint?

print does not add a new line. p shows the string with quotes.

4
Use puts, print, and p to display the number
Use puts number, print number, and p number to display the variable number.
Ruby
Need a hint?

Numbers print without quotes. p shows the number as is.