CSCI 127 Hunter College Strings Iteration and Recursion Lab Report Logistics
Due: Thursday, May 28th no later than 5pm.
Submission instructions: upload your solution, entitled FirstName-LastName-Lab3.py to the BrightSpace Lab 3 Dropbox.
Deadline reminder: once this deadline passes, BrightSpace will no longer accept your Python submission and you will no longer be able to earn credit. Thus, if you are not able to fully complete the assignment, submit whatever you have before the deadline so that partial credit can be earned.
Learning outcomes
Gain experience manipulating strings.
Gain experience solving a problem using iteration.
Gain experience solving a problem using recursion.
Assignment
Download lab3.py and rename it according to the instructions above.
Rewrite the body of the length_built_in function to calculate and return the length of the paramter sentence using the built-in len function (see the documentation here). For example, if the sentence is “Montana State”, the function should return 13.
Rewrite the body of the length_iterative function to compute the length of sentenceusing a loop. (Do not use the built-in length function.)
Rewrite the body of the length_recursive function to compute the length of sentenceusing recursion. (Do not use the built-in length function.)
Grading – 10 points
3 points – the length_built_in function is implemented correctly.
3 points – the length_iterative function is implemented correctly.
4 points – the base case (2 points) and 2 general cases (1 point each) of the recursive function are implemented correctly.
Grading turnaround
All labs graded with scores recorded in BrightSpace no later than lab time (2pm) the following day.
# ————————————–
# CSCI 127, Lab 3 |
# May 28, 2020 |
# ————————————–
# Calculate the length of a string |
# using three techniques. |
# ————————————–
def length_built_in(sentence):
pass
def length_iterative(sentence):
pass
def length_recursive(sentence):
pass
# ————————————–
def main():
answer = “yes”
while (answer == “yes”) or (answer == “y”):
sentence = input(“Please enter a sentence: “)
sentence = sentence.lower()
print()
print(“Calculating length of the sentence using …”)
print(“—————————————“)
print(“Built-in function =”, length_built_in(sentence))
print(“Iteration =”, length_iterative(sentence))
print(“Recursion =”, length_recursive(sentence))
print()
answer = input(“Would you like to continue: “).lower()
print()
# ————————————–
main()
Economic Debate- Progressive Income Tax For this Economic Debate, we are going to discuss the…
TOPIC: Going Global Discussion Thread 1 (initial post due Wednesday for full credit) Please note:…
Assignment Topic This week will culminate in the creation of a narrated PowerPoint to create…
The Assignment must be submitted on Blackboard (WORD format only) via allocated folder. Assignments submitted…
you need to post your 2-page information flier to share with your Final Project Group.…
discussion: Discuss the methods used at your company to measure and ensure quality products and…