Jun-10-2020, 09:16 PM
Hi,
New to coding in my first class. Catching on but have no clue how to attack this problem I have now.
I am tasked with The user should be prompted to enter a word, phrase, sentence or number into an input string
TIP: Use a repetition loop (for) to go through each letter of the input, e.g.:
for xyz in myString: will loop through each character of the myString variable. You can then examine the character in a conditional structures (use complex Booleans – and/or) to determine if the character is a letter or a number, concatenate it to two strings (one forwards, one backwards) while removing the case sensitivity (upper or lower methods). Then compare the two strings to determine if they are equivalent and report out (print) accordingly. You may not use any features not yet covered in this course, such as lists, tuples, functions.
What I have so far is
In a loop, make a new phrase that removes all spaces and punctuation.
It should keep only A-Z and 0-9 (make case insensitive)
You can create a reversed string at the same time as removing the spaces/punctuation (just concatenate the new character in front of the current state of the reversed string.
I'm not sure who to only use the A-Z and 0-9 without using functions.
Here is my output
Enter a work, phrase, sentence, or number (or 0 to end) :racecar
Yes, racecar is indeed a palidrome
Enter a work, phrase, sentence, or number (or 0 to end) :mike
No, mike is not a palidrome
Enter a work, phrase, sentence, or number (or 0 to end) :0
Good Bye!
>>>
As posted I don't know where to begin using a loop to strip backspaces and special characters from the user input
New to coding in my first class. Catching on but have no clue how to attack this problem I have now.
I am tasked with The user should be prompted to enter a word, phrase, sentence or number into an input string
TIP: Use a repetition loop (for) to go through each letter of the input, e.g.:
for xyz in myString: will loop through each character of the myString variable. You can then examine the character in a conditional structures (use complex Booleans – and/or) to determine if the character is a letter or a number, concatenate it to two strings (one forwards, one backwards) while removing the case sensitivity (upper or lower methods). Then compare the two strings to determine if they are equivalent and report out (print) accordingly. You may not use any features not yet covered in this course, such as lists, tuples, functions.
What I have so far is
print("Assignment 09 Palindrome Tester\n") print("""This program accepts a word, phrase, sentence, or number from the user and determines whether it is a palindrome or not. A palindrome would read the same backwards as forwards, ignoring any spaces or puncuation and is case-sensitive. A few examples: - Bob - 1234321 - Madam, I'm Adam! - Was It A Rat I Saw? - Mr. Owl Ate My Metal Worm\n""") pal = 2 while pal != "0": pal = input("Enter a work, phrase, sentence, or number (or 0 to end) :") if pal != "0": originalPal = str(pal) reversedPal = "" for x in range(0,len(originalPal)): reversedPal = originalPal[x] + reversedPal if originalPal.lower() == reversedPal.lower(): print("Yes, {0} is indeed a palidrome\n".format(reversedPal)) else: print("No, {0} is not a palidrome\n".format(pal)) else: print("Good Bye!")Everything works so far but I have no clue how to approach stripping out the special char and blank spaces in the user input statement. The professor gave hints:
In a loop, make a new phrase that removes all spaces and punctuation.
It should keep only A-Z and 0-9 (make case insensitive)
You can create a reversed string at the same time as removing the spaces/punctuation (just concatenate the new character in front of the current state of the reversed string.
I'm not sure who to only use the A-Z and 0-9 without using functions.
Here is my output
Enter a work, phrase, sentence, or number (or 0 to end) :racecar
Yes, racecar is indeed a palidrome
Enter a work, phrase, sentence, or number (or 0 to end) :mike
No, mike is not a palidrome
Enter a work, phrase, sentence, or number (or 0 to end) :0
Good Bye!
>>>
As posted I don't know where to begin using a loop to strip backspaces and special characters from the user input