0
0
Pythonprogramming~10 mins

String creation and representation 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 create a string variable named greeting with the value Hello.

Python
greeting = [1]
Drag options to blanks, or click blank then click option'
A'Hello'
B"Hello"
CHello
DHello"
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Forgetting to put quotes around the string.
Using mismatched or missing quotes.
2fill in blank
medium

Complete the code to create a multi-line string using triple quotes.

Python
text = [1]This is line one.
This is line two.
[2]
Drag options to blanks, or click blank then click option'
A"""
B'''
C'
D"
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using single or double quotes instead of triple quotes.
Not closing the triple quotes.
3fill in blank
hard

Fix the error in the code to correctly print a string with a quote inside.

Python
print([1])
Drag options to blanks, or click blank then click option'
A"It's a sunny day"
B'It's a sunny day'
C'It\'s a sunny day'
D"It\'s a sunny day"
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Not escaping the single quote inside single quotes causes an error.
Using mismatched quotes.
4fill in blank
hard

Fill both blanks to create a string that includes a newline character and prints correctly.

Python
message = [1] + [2]
print(message)
Drag options to blanks, or click blank then click option'
A"Hello\n"
B"Hello"
C"World"
D"\nWorld"
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Not including the newline character.
Putting the newline character in the wrong place.
5fill in blank
hard

Fill all three blanks to create a formatted string using f-string syntax that shows a name and age.

Python
name = "Alice"
age = 30
info = [1]"Name: [2], Age: [3]" 
print(info)
Drag options to blanks, or click blank then click option'
Af
Bname
Cage
DF
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Forgetting the f prefix.
Not using curly braces around variables.
Using uppercase F instead of lowercase f (both work but only one is correct here).