To find the length of a python string you can use the function size length len numItems
Added by Gary C.
Step 1
Step 1: Identify the function used to determine the length of a string in Python. Show more…
Show all steps
Your feedback will help us improve your experience
Akash M and 91 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
In Python, write code to assign the number of characters in the string "rv" to a variable called "num_chars.
Akash M.
For this task, you need to write MARIE code that can print any string (no matter how long) using the Output instruction. Start by using a label "PrintCharactersRemaining" that you initialize with the size of the string (which is stored in the first memory location of the string). In addition, the code needs to use a label "CurrentCharacterLocation" that is initialized to the memory location of the first character of the string, i.e., the location after where the size is stored. The code should then check if there are characters remaining to be printed. If no more characters are available, we have reached the end of the string and can Halt. If more characters are available, the code outputs the character stored at CurrentCharacterLocation, increments CurrentCharacterLocation by one, decrements PrintCharactersRemaining by one, and loops back to the test whether any characters are remaining.
Supreeta N.
Printing a string (3 points) For this task, you need to write MARIE code that can print any string (no matter how long) using the Output instruction. Start by using a label "PrintCharactersRemaining" that you initialize with the size of the string (which is stored in the first memory location of the string). In addition, the code needs to use a label "CurrentCharacterLocation" that is initialized to the memory location of the first character of the string, i.e., the location after where the size is stored. The code should then check if there are characters remaining to be printed. If no more characters are available, we have reached the end of the string and can Halt. If more characters are available, the code outputs the character stored at "CurrentCharacterLocation", increments "CurrentCharacterLocation" by one, decrements "PrintCharactersRemaining" by one, and loops back to the test whether any characters are remaining. Submit your MARIE code that shows the test case of printing your name from the previous task. (You only have to submit one file that includes your solutions to Tasks 2.1 and 2.2).
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD