0
0
Rustprogramming~10 mins

Compilation and execution flow in Rust - 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
BHello, world!
C'Hello, world!'
D"Hello, world!"
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Forgetting the double quotes around the string.
Using single quotes instead of double quotes.
2fill in blank
medium

Complete the code to declare a variable named x with value 5.

Rust
fn main() {
    let [1] = 5;
    println!("{}", x);
}
Drag options to blanks, or click blank then click option'
Ax
Bvalue
Cnum
Dfive
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using a different variable name than the one printed.
Forgetting to declare the variable.
3fill in blank
hard

Fix the error in the code to correctly add two numbers and print the result.

Rust
fn main() {
    let a = 3;
    let b = 4;
    let sum = a [1] b;
    println!("{}", sum);
}
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Using an invalid operator.
4fill in blank
hard

Fill both blanks to create a loop that prints numbers from 1 to 5.

Rust
fn main() {
    for i in [1] [2] 6 {
        println!("{}", i);
    }
}
Drag options to blanks, or click blank then click option'
A1..
B1..=
C6..
D..
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 1..=6 which includes 6 and prints 6 as well.
Using 6..1 which is an invalid range.
5fill in blank
hard

Fill all three blanks to create a function that returns the square of a number.

Rust
fn square([1]: i32) -> i32 {
    [2] * [3]
}

fn main() {
    let result = square(4);
    println!("{}", result);
}
Drag options to blanks, or click blank then click option'
Anum
Dx
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using different variable names inside the function.
Forgetting to return the multiplication result.