Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to convert the string "123" to a number.
Terraform
number_value = [1]("123")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'tostring' instead of 'tonumber'.
Forgetting to use a conversion function.
✗ Incorrect
The function tonumber converts a string to a number in Terraform.
2fill in blank
mediumComplete the code to convert the number 456 to a string.
Terraform
string_value = [1](456)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'tonumber' instead of 'tostring'.
Using list or map conversion functions by mistake.
✗ Incorrect
The function tostring converts a number to a string in Terraform.
3fill in blank
hardFix the error in the code to convert a list of strings to a list of numbers.
Terraform
numbers = [for s in string_list : [1](s)]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'tostring' which converts to string, not number.
Using 'tolist' or 'tomap' which are for collections.
✗ Incorrect
Use 'tonumber' to convert each string in the list to a number.
4fill in blank
hardFill both blanks to convert a map of strings to a map of numbers.
Terraform
numbers_map = { for k, v in string_map : k => [1](v) if [2](v) != null } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'tostring' instead of 'tonumber'.
Using 'length' which returns number of characters, not conversion.
✗ Incorrect
Use 'tonumber' to convert values and check if conversion is not null.
5fill in blank
hardFill all three blanks to convert a list of mixed strings to a list of numbers, skipping invalid entries.
Terraform
valid_numbers = [for s in mixed_list : [1](s) if [2](s) != null and [3](s) != ""]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'tostring' instead of 'tonumber'.
Not trimming spaces before checking for empty strings.
✗ Incorrect
Convert strings to numbers, check conversion is not null, and skip empty strings after trimming spaces.