0
0
Rustprogramming~10 mins

Character type 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 declare a character variable with the letter 'a'.

Rust
let letter: char = '[1]';
Drag options to blanks, or click blank then click option'
A'a'
B'ab'
Ca
D"a"
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using double quotes instead of single quotes.
Not using quotes at all.
Using more than one character inside quotes.
2fill in blank
medium

Complete the code to print the Unicode code point of the character 'Z'.

Rust
let ch: char = 'Z';
println!("{}", ch [1] u32);
Drag options to blanks, or click blank then click option'
Ato_digit
Bto_ascii_uppercase
Cto_string
Das
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using to_digit without an argument.
Trying to call a method that doesn't exist for char.
Using string methods instead of char methods.
3fill in blank
hard

Fix the error in the code to check if a character is a digit.

Rust
let c = '5';
if c.[1]() {
    println!("It's a digit!");
}
Drag options to blanks, or click blank then click option'
Ais_alphanumeric
Bis_digit
Cis_numeric
Dis_alphabetic
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using is_digit() without arguments (it requires a radix).
Using is_alphabetic() which checks for letters.
4fill in blank
hard

Fill both blanks to create a map from characters to their uppercase versions for letters only.

Rust
let letters = ['a', 'b', 'c', '1'];
let uppercase_map: std::collections::HashMap<char, char> = letters.iter()
    .filter(|&&c| c.[1]())
    .map(|&c| (c, c.[2]()))
    .collect();
Drag options to blanks, or click blank then click option'
Ais_alphabetic
Bto_ascii_uppercase
Cis_numeric
Dto_lowercase
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Filtering numeric characters instead of alphabetic.
Using to_lowercase() instead of uppercase.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps characters to their Unicode code points if they are digits.

Rust
let chars = ['a', '3', '7', 'b'];
let digit_map: std::collections::HashMap<char, u32> = chars.iter()
    .filter(|&&c| c.[1]())
    .map(|&c| (c, c [2] [3]))
    .collect();
Drag options to blanks, or click blank then click option'
Ais_numeric
Bas
Cu32
Dis_alphabetic
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using is_alphabetic() instead of is_numeric().
Forgetting to cast the character to u32.