0
0
Swiftprogramming~10 mins

Int, Double, Float number types in Swift - 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 an integer variable named age with value 25.

Swift
var age: [1] = 25
Drag options to blanks, or click blank then click option'
ADouble
BInt
CFloat
DString
Attempts:
3 left
💡 Hint
Common Mistakes
Using Double or Float for whole numbers when Int is more appropriate.
Using String instead of a number type.
2fill in blank
medium

Complete the code to declare a variable price with a decimal number type that uses less memory than Double.

Swift
var price: [1] = 19.99
Drag options to blanks, or click blank then click option'
AFloat
BDouble
CInt
DBool
Attempts:
3 left
💡 Hint
Common Mistakes
Using Int for decimal numbers causes errors.
Choosing Double when Float is enough.
3fill in blank
hard

Fix the error in the code by choosing the correct type for temperature that can hold decimal values.

Swift
var temperature: [1] = 36.6
Drag options to blanks, or click blank then click option'
ABool
BString
CInt
DDouble
Attempts:
3 left
💡 Hint
Common Mistakes
Using Int causes loss of decimal part.
Using String or Bool causes type errors.
4fill in blank
hard

Fill both blanks to create a variable weight with a decimal type and assign it the value 70.5.

Swift
var weight: [1] = [2]
Drag options to blanks, or click blank then click option'
ADouble
B70.5
CFloat
DInt
Attempts:
3 left
💡 Hint
Common Mistakes
Using Int type with decimal value causes errors.
Assigning integer value to a decimal type variable.
5fill in blank
hard

Fill all three blanks to declare a constant pi with type Double and value 3.14159.

Swift
let [1]: [2] = [3]
Drag options to blanks, or click blank then click option'
Api
BDouble
C3.14159
DFloat
Attempts:
3 left
💡 Hint
Common Mistakes
Using var instead of let for constants.
Using Float instead of Double for precision.
Assigning integer value instead of decimal.