Last active
October 4, 2023 17:12
-
-
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.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """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 | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hih