Complete the code to print "Positive" if the number is greater than zero.
let number = 5; if number [1] 0 { println!("Positive"); }
The condition number > 0 checks if the number is positive.
Complete the code to assign the string "even" or "odd" based on the number.
let number = 4; let result = if number % 2 [1] 0 { "even" } else { "odd" };
The expression number % 2 == 0 checks if the number is even.
Fix the error in the if expression to correctly assign the maximum of two numbers.
let a = 10; let b = 20; let max = if a [1] b { b } else { a };
a as max incorrectly.The condition a < b means if a is less than b, then b is the max.
Fill in the blank to create a dictionary with word lengths for words longer than 3 letters.
let words = ["cat", "house", "dog", "elephant"]; let lengths = words.iter() .filter(|&word| word.len() [1] 3) .map(|word| (word, word.len())) .collect::<std::collections::HashMap<_, _>>();
The word.len() > 3 filters words longer than 3 letters.
Fill the blanks to create a HashMap of uppercase words and their lengths for words longer than 4 letters.
let words = ["apple", "bat", "carrot", "dog"]; let result = words.iter() .filter(|&word| word.len() [1] 4) .map(|word| (word.[2](), word.len())) .collect::<std::collections::HashMap<_, _>>();
The filter selects words longer than 4 letters, then maps each word to its uppercase form and length.