0
0
Rustprogramming~10 mins

Relational operators 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 check if a is less than b.

Rust
let a = 5;
let b = 10;
let result = a [1] b;
println!("{}", result);
Drag options to blanks, or click blank then click option'
A>=
B<
C==
D>
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using > instead of < will check the opposite condition.
2fill in blank
medium

Complete the code to check if x is equal to y.

Rust
let x = 7;
let y = 7;
let is_equal = x [1] y;
println!("{}", is_equal);
Drag options to blanks, or click blank then click option'
A==
B!=
C>
D<
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using = instead of == assigns a value instead of comparing.
3fill in blank
hard

Fix the error in the code to check if num is not equal to 0.

Rust
let num = 3;
let check = num [1] 0;
println!("{}", check);
Drag options to blanks, or click blank then click option'
A==
B<=
C!=
D>=
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using == will check for equality, not inequality.
4fill in blank
hard

Fill the blank to create a dictionary with words as keys and their lengths as values, only for words longer than 3 letters.

Rust
let words = ["apple", "cat", "banana", "dog"];
let lengths = words.iter().filter(|&&word| word.len() [1] 3).map(|&word| (word, word.len())).collect::<std::collections::HashMap<_, _>>();
Drag options to blanks, or click blank then click option'
A>
B<
C==
D!=
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using < will select shorter words instead.
5fill in blank
hard

Fill the blanks to create a HashMap with uppercase keys and values greater than 2.

Rust
let data = vec![("one", 1), ("two", 2), ("three", 3)];
let filtered: std::collections::HashMap<_, _> = data.into_iter()
    .filter(|&(_, v)| v [1] 2)
    .map(|(k, v)| (k.[2](), v))
    .collect();
Drag options to blanks, or click blank then click option'
A<
B>
Cto_uppercase
Dto_lowercase
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using < will filter wrong values.
Using to_lowercase will not convert keys to uppercase.