Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a 32-bit floating point variable.
Rust
let pi: [1] = 3.14f32;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using integer types like i32 for floating point numbers.
Using boolean or character types for numbers.
โ Incorrect
The f32 type is used for 32-bit floating point numbers in Rust.
2fill in blank
mediumComplete the code to declare a 64-bit floating point variable.
Rust
let e: [1] = 2.71828;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using integer types like i64 instead of floating point.
Confusing usize with floating point types.
โ Incorrect
The f64 type is used for 64-bit floating point numbers in Rust.
3fill in blank
hardFix the error in the code by choosing the correct floating point type.
Rust
let gravity: [1] = 9.81;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using non-existent types like f128 or int.
Using string types for numbers.
โ Incorrect
Rust supports f32 and f64 for floating point types. f64 is the correct 64-bit type.
4fill in blank
hardFill both blanks to create a vector of 32-bit floating point numbers.
Rust
let numbers: Vec<[1]> = vec![1.0f32, 2.0f32, 3.0f32]; let first: [2] = numbers[0];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Mixing integer and floating point types.
Using
f64 when the vector is f32.โ Incorrect
The vector holds f32 values, so the variable first must also be f32.
5fill in blank
hardFill all three blanks to create a function that returns a 64-bit floating point number.
Rust
fn calculate_area(radius: [1]) -> [2] { let pi: [3] = 3.14159; pi * radius * radius }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Mixing
f32 and f64 types.Using integer types for floating point calculations.
โ Incorrect
The function uses f64 for the parameter, return type, and constant pi for precision.