Why is input important for a program?
Think about how a program can change its behavior based on what the user types.
Input allows a program to get data from outside, like user answers or files, so it can do useful work.
Why is output important for a program?
Think about how a program tells you what it did or found.
Output is how a program communicates results, messages, or data back to the user or other programs.
Look at this Rust code. What will it print?
fn main() {
let name = "Alice";
println!("Hello, {}!", name);
}Look at how the variable name is used inside the println! macro.
The {} is replaced by the value of name, which is "Alice".
What error will this Rust code cause?
fn main() {
let mut input = String::new();
std::io::stdin().read_line(&mut input).expect("Failed to read line");
println!("You typed: {}", input);
}Check if the code handles the result of read_line.
The read_line function returns a Result that must be handled or ignored explicitly. Missing this causes a warning or error.
Choose the best explanation why input and output are essential for interactive programs.
Think about how programs talk with people in real time.
Interactive programs need input to get user commands or data, and output to show responses or results, enabling a conversation-like experience.