Skip to content

Colaboratory Notebook Problem: Lesson 5 Practice Problems, Reversing a string #296

@mikaturner

Description

@mikaturner

The colaboratory notebook version of this only has the answer and not the practice problem or test assertions.

This is what is in the notebook version:
def reverse_string(input):
answer = ""
# Your code goes here

for letter in input:
  answer = letter + answer
#  End of your code
return answer

reverse_string("hola")


This is what is in the correct GitHub version:

def reverse_string(input_str):
answer = ""
# Your code goes here

#  End of your code
return answer

Tests below, do not change

assert reverse_string("hello") == "olleh", "Cannot reverse 'hello'"
assert reverse_string("") == "", "When given an empty string it returns an empty string, but doesn't"
assert reverse_string("racecar") == "racecar", "Cannot reverse 'racecar'"
assert reverse_string("12345") == "54321", "Cannot reverse 12345"

If the program gets here, the code works!

print("Your solution works!")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions