0
0
Rustprogramming~10 mins

Writing first Rust program - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print "Hello, world!" in Rust.

Rust
fn main() {
    println!([1]);
}
Drag options to blanks, or click blank then click option'
AHello, world!
B"Hello, world!"
Cprintln!("Hello, world!")
Dprint!("Hello, world!")
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Forgetting the quotes around the text.
Using print! instead of println! for a new line.
2fill in blank
medium

Complete 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'
Amain
Bbegin
Cstart
Drun
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using a different function name instead of main.
Forgetting the parentheses after the function name.
3fill in blank
hard

Fix 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'
Aprint!("Hello, Rust!")
BHello, Rust!
Cprintln!("Hello, Rust!")
D"Hello, Rust!"
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Leaving out the quotes causes a compile error.
Using print! instead of println! changes output formatting.
4fill in blank
hard

Fill 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'
Agreet
B"Welcome to Rust!"
C"Hello, friend!"
Dmain
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using a message without quotes.
Using main as function name when a different name is asked.
5fill in blank
hard

Fill 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'
Amain
B"Rust is fun!"
Cmessage
D"Hello from Rust!"
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.