0
0
Rustprogramming~10 mins

Integer types 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 32-bit signed integer variable named num with the value 10.

Rust
let num: [1] = 10;
Drag options to blanks, or click blank then click option'
Af32
Bu32
Ci32
Dbool
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using u32 which is unsigned and might not be intended here.
Using floating point types like f32 for integers.
2fill in blank
medium

Complete the code to declare an unsigned 8-bit integer variable named age with the value 25.

Rust
let age: [1] = 25;
Drag options to blanks, or click blank then click option'
Au8
Bi16
Cbool
Di8
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using signed types like i8 which allow negative numbers.
Using boolean type bool which is not numeric.
3fill in blank
hard

Fix the error in the code by choosing the correct integer type for the variable count initialized with 1000.

Rust
let count: [1] = 1000;
Drag options to blanks, or click blank then click option'
Ai16
Bu8
Ci8
Dbool
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using i8 or u8 which are too small for 1000.
Using bool which is not numeric.
4fill in blank
hard

Fill both blanks to create a dictionary that maps numbers to their squares for numbers 1 to 3, using the correct integer types and operators.

Rust
let squares = std::collections::HashMap::from([(1[1] 3, 1[2] 3)]);
Drag options to blanks, or click blank then click option'
A..=
B*
C+
D-
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using .. which excludes the last number.
Using addition or subtraction instead of multiplication for squares.
5fill in blank
hard

Fill both blanks to create a HashMap that stores the length of each word only if the length is greater than 3.

Rust
let lengths = words.iter().filter(|&word| word.len() [1] 3).map(|word| (word.to_string(), word.len() [2] ,)).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 incorrect comparison operators in filter.
Not separating tuple elements with a comma.
Using addition instead of subtraction for length adjustment.