# Quiz: Python Strings

### Instructions

Complete and submit the following exercises:

``````# Set a different value for 'str' to get the right answer.

str = ''

# 1. Length
# The length should be 20
print("Length of str = ", len(str))

# 2. Positions
# This will display the second letter:
print(str[1])
# Now, show the third letter

# 3. Index
# Display the position of the first match with the letter a
# It should print 1
print("First position of the letter a = ", str.index("a"))

# 4. Count
# Count at least 5 letters a
print("It has ", s.count("a"))

# 5. Print in rows
# Print every letter of the string

# 6. For the next exercise, leave the value of `str` as it is
# and use methods to change the given string to lower case,
# print it, then change it to upper case and print it

str = "HeLLo, hOW aRe YoU?"

# Tip: search for the different Python String Methods
``````

## Example of how a solution must be submitted

Here’s an example of how the solution should be laid out:

Let’s see the first exercise:

``````# Set a different value for 'str' to get the right answer.

str = ''

# 1. Length
# The length should be 20
print("Length of str = ", len(str))
``````

Your solution will look like this:

``````# Set a different value for 'str' to get the right answer.

str = ''

# 1. Length
# The length should be 20
str = "twentycharactershere"
print("Length of str = ", len(str))
``````

UPDATED: 12.04.2021

## 9 replies on “Quiz: Python Strings”

can you tell me what was the problem exactly?

You should change the value of the str variable so that the tests complete succesfully.

Noraldin Saied Alshkakisays:

How am I meant to know what the value of str should be?

Each task, numbered from 1 to 6 contains a description and some lines of code that expect the value of str to changed accordingly.

For example “# The length should be 20”

print(“Length of str = “, len(str))

In this case you must change the value of str to a string with length 20 in order to complete the task.

Nick Papamichailsays:

I’m a bit confused. I submitted my code for all the exercises but the results were “0 out of 1 questions answered correctly”. Do I have to answer the exercises one by one, wait for the result and then go to the next one and so on? Or, do I have to submit a file like “Quiz1.py”?

Everything is OK at this point. The reason why you see the “0 out of 1 questions answered correctly” message is because these exercises will be graded later. Don’t worry about the message now, you can continue with the rest of the precourse.

Hermessays:

I’m not sure what we were supposed to do for #5. I left it the same since the print function automatically inserts a new line character, so it prints the letters on their own row.

Updated. Thank you for pointing this out to us. Good luck with the rest of the course!