Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define the main function in Rust.
Rust
fn [1]() { println!("Hello, world!"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using a different function name instead of main.
Adding parameters to the main function.
โ Incorrect
The main function is the entry point of a Rust program.
2fill in blank
mediumComplete the code to print a message inside the main function.
Rust
fn main() {
[1]!("Welcome to Rust!");
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using
print which does not add a newline.Trying to use functions instead of macros.
โ Incorrect
The println! macro prints text with a newline at the end.
3fill in blank
hardFix the error in the function declaration to make it valid Rust code.
Rust
fn main[1] { println!("Fixed function"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Omitting parentheses after the function name.
Using braces
{} instead of parentheses.โ Incorrect
Functions in Rust require parentheses () after the name, even if no parameters.
4fill in blank
hardFill both blanks to create a valid Rust program that prints a message.
Rust
fn [1]() { [2]!("Hello from Rust!"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using incorrect function names.
Using
print instead of println.โ Incorrect
The program needs the main function and the println! macro to print the message.
5fill in blank
hardFill all three blanks to define a main function that prints a formatted message.
Rust
fn [1]() { [2]!("Number: {}", [3]); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using
print instead of println.Not providing a value for the placeholder.
โ Incorrect
The main function uses println! macro to print the number 42 formatted inside the string.