Menu

[solved]-1 String Called Mystring Want Display 5th Letter 9th Letter String Using Indexing Finished Q39043439

1) We have a string called my_string and we want to display the5th letter and the 9th letter of the string usingindexing.  When you are finished, youroutput will match that under Desired Output.

# Create String
my_string = “Python rocks!”

# display the 5th and 9th characters of
# /my_string/ using indexing
desired output:

oo

2)We have a string called my_string and we want to display the5th-to-last letter and the 9th-to-last letter of the string usingnegative indexes.  When you arefinished, your output will match that under DesiredOutput.

# Create String
my_string = “Python rocks!”

# display the 5th-to-last and 9th-to-last characters of
# /my_string/ using negative indexes

desired output:

oo

3)

We have a string called my_string and we want to display it oneletter at a time.

  1. Use a while loop to display each letter ofmy_string.  
  2. Use the length of my_string to prevent an error frombeing thrown
  3. Don’t forget to increment the variable index, or you willcreate an infinite loop and crash your browser.

When you are finished, your output will match that underDesired Output.

# Create String
my_string = “Python rocks!”

# Instantiate /index/
index = 0

# Use a /while/ loop and the length
# of the string /my_string/ to display
# /my_string/ one character at a time
#
# WARNING! Don’t create an infinite loop or
# your browser will crash

print(my_string[index])

desired output:

Python rocks!

4)We have a string called my_string and we want to display itone letter at a time. Use a for loop to display each letter ofmy_string. When you are finished, your output will match that underDesired Output.

# Create String
my_string = “Python rocks!”

# use a /for/ loop to display
# /my_string/ one character at
# a time
desired output:

Python rocks!

Expert Answer


Answer to 1) We have a string called my_string and we want to display the 5th letter and the 9th letter of the string using indexi… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *