Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print "Hello, world!" in Rust.
Rust
fn main() {
println!([1]);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Forgetting the quotes around the text.
Using print! instead of println! for a new line.
โ Incorrect
The println! macro prints text to the screen. The text must be inside double quotes.
2fill in blank
mediumComplete the code to declare the main function in Rust.
Rust
fn [1]() { println!("Hello from Rust!"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using a different function name instead of main.
Forgetting the parentheses after the function name.
โ Incorrect
The entry point of a Rust program is the main function.
3fill in blank
hardFix the error in the code to correctly print a message.
Rust
fn main() {
println!([1]);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Leaving out the quotes causes a compile error.
Using print! instead of println! changes output formatting.
โ Incorrect
The argument to println! must be a string literal enclosed in double quotes.
4fill in blank
hardFill both blanks to create a function that prints a greeting.
Rust
fn [1]() { println!([2]); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using a message without quotes.
Using
main as function name when a different name is asked.โ Incorrect
The function name can be greet, and the message must be a string literal like "Hello, friend!".
5fill in blank
hardFill all three blanks to print a custom message inside the main function.
Rust
fn [1]() { let message = [2]; println!([3]); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Printing the string literal directly instead of the variable.
Using wrong function name or missing quotes around the string.
โ Incorrect
The main function is named main. The variable message holds the string "Rust is fun!". The println! macro prints the variable message.