0
0
Pythonprogramming~10 mins

Escape characters in output in Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print a new line between words.

Python
print("Hello[1]World")
Drag options to blanks, or click blank then click option'
A\r
B\n
C\\
D\t
Attempts:
3 left
💡 Hint
Common Mistakes
Using \t which adds a tab space instead of a new line.
Using \\ which prints a backslash.
Using \r which returns the cursor to the start of the line.
2fill in blank
medium

Complete the code to print a tab space between words.

Python
print("Hello[1]World")
Drag options to blanks, or click blank then click option'
A\t
B\r
C\n
D\\
Attempts:
3 left
💡 Hint
Common Mistakes
Using \n which adds a new line instead of a tab.
Using \\ which prints a backslash.
Using \r which returns the cursor to the start of the line.
3fill in blank
hard

Fix the error in the code to print a backslash character.

Python
print("This is a backslash: [1]")
Drag options to blanks, or click blank then click option'
A\
B\t
C\n
D\\
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single backslash \ which causes an error or escape sequence.
Using \n or \t which print new line or tab instead.
4fill in blank
hard

Fill both blanks to print a quote inside a string.

Python
print("She said, [1]Hello[2]")
Drag options to blanks, or click blank then click option'
A\"
B\'
C"
D'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unescaped double quotes which break the string.
Using single quotes which won't print double quotes.
5fill in blank
hard

Fill all three blanks to print a file path with backslashes.

Python
print("C:[1]Users[2]Documents[3]file.txt")
Drag options to blanks, or click blank then click option'
A\/
B\\
C\
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using single backslash \ which causes errors.
Using forward slash / which is different from backslash.