Skip to content

Instantly share code, notes, and snippets.

@InquisitiveDev2016
Last active October 4, 2023 17:12
Show Gist options
  • Select an option

  • Save InquisitiveDev2016/6fdbfd41bafd3ab9e5fbdf18d4bca7ca to your computer and use it in GitHub Desktop.

Select an option

Save InquisitiveDev2016/6fdbfd41bafd3ab9e5fbdf18d4bca7ca to your computer and use it in GitHub Desktop.
Ask the user for a string and print out whether this string is a palindrome or not. (A palindrome is a string that reads the same forwards and backwards.)
"""1.) Understand the problem
Ask the user for a string and print out whether this string is a palindrome or not.
(A palindrome is a string that reads the same forwards and backwards.)
2.) Plan a solution
Algorithm:
- Treat the string as a list
- Iterate through the list
- if the string is equal forwards as it is backwards
- print the entire string
- else
- print error
3.) Carry out the plan
"""
name = input("Give me a word and I'll tell you if it's a palindrome")
if name[::-1] == name[0:]:
print(name, " is a palindrome")
else:
print(name, " is not a palindrome")
"""
4.) Examine your results for accuracy:
Input:
name = racecar
name = apple
Output:
racecar is a palindrome
apple is not a palindrome
"""
@raneemyaseen
Copy link

hih

@smkiptum
Copy link

smkiptum commented Oct 4, 2023

So helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment