Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a tuple with an integer and a string.
Rust
let my_tuple = ([1], "hello");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using a string instead of an integer for the first element.
โ Incorrect
The tuple should start with an integer, so 42 is correct.
2fill in blank
mediumComplete the code to access the second element of the tuple.
Rust
let second = my_tuple.[1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using index 2 or higher which is out of range for a two-element tuple.
โ Incorrect
Tuple elements are accessed by zero-based index, so the second element is at index 1.
3fill in blank
hardFix the error in the code to create an array of integers.
Rust
let numbers: [i32; 3] = [[1], 2, 3];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using a string or float instead of an integer.
โ Incorrect
The array must contain integers, so 1 is the correct choice.
4fill in blank
hardFill both blanks to create a vector and add an element to it.
Rust
let mut v = Vec::new(); v.[1](10); let first = v.[2](0);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using
pop to add elements or insert without index.โ Incorrect
Use push to add an element and get to access an element by index.
5fill in blank
hardFill all three blanks to create a tuple, destructure it, and print the values.
Rust
let [1] = ("Rust", 2024); let (language, year) = [2]; println!("{} was released in {}", [3], year);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using different variable names for the tuple and destructuring.
Printing the tuple variable instead of the destructured value.
โ Incorrect
We name the tuple info, destructure info, and print language.