0
0
Swiftprogramming~20 mins

Print function for output in Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Swift Print Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Swift print statement?
Look at the code below. What will it print when run?
Swift
print("Hello, \"Swift\" world!")
AHello, 'Swift' world!
BHello, "Swift" world!
CHello, Swift world!
DHello, \"Swift\" world!
Attempts:
2 left
💡 Hint
Remember how escape characters work in strings.
Predict Output
intermediate
2:00remaining
What does this Swift code print?
Check the code and choose the correct output.
Swift
let name = "Anna"
print("Hello, \(name)!")
AHello, Anna!
BHello, \(name)!
CHello, name!
DHello, (name)!
Attempts:
2 left
💡 Hint
Look at how Swift uses \(variable) inside strings.
Predict Output
advanced
2:00remaining
What is the output of this Swift code with multiple print statements?
Analyze the code and select the correct output sequence.
Swift
print("Line 1")
print("Line 2", terminator: " ")
print("Line 3")
A
Line 1
Line 2 Line 3
B
Line 1 Line 2 Line 3
C
Line 1
Line 2
Line 3
D
Line 1 Line 2
Line 3
Attempts:
2 left
💡 Hint
Check how the terminator parameter changes the print behavior.
Predict Output
advanced
2:00remaining
What will this Swift code print?
Consider the code and pick the correct output.
Swift
let number = 5
print("Number is \(number * 2)")
ANumber is 5 * 2
BNumber is number * 2
CNumber is 10
DNumber is \(number * 2)
Attempts:
2 left
💡 Hint
Swift evaluates expressions inside \( ) in strings.
Predict Output
expert
3:00remaining
What is the output of this Swift code using multiline string and print?
Look carefully at the code and select the exact output.
Swift
let poem = """
Roses are red,
Violets are blue,
Swift is fun,
And so are you.
"""
print(poem)
ARoses are red,\nViolets are blue,\nSwift is fun,\nAnd so are you.
BRoses are red, Violets are blue, Swift is fun, And so are you.
C"Roses are red,\nViolets are blue,\nSwift is fun,\nAnd so are you."
D
Roses are red,
Violets are blue,
Swift is fun,
And so are you.
Attempts:
2 left
💡 Hint
Multiline strings keep line breaks as they are.