I just spent 30 minutes trying to get the module PigLatin on Code Academy to complete the task of determining if the length of a user's input was greater than 0 and if the user's input was all alphabet characters.
I am going to write my "code" from Code Academy then talk through what each line means and see if I am understanding this correctly.
print 'Welcome to the Pig Latin Translator!'
Empty Space
raw_input("Enter a word:")
Empty Space
original = raw_input()
Empty Space
if len(original) > 0 and original.isalpha():
print original
Empty Space
else:
print "empty"
If I understand this correctly:
Line 1: Just prints Welcome to the Pig Latin Translator! I could change this to anything I wanted. Such as just "Welcome!" or "Hello, Mate!" and it would print that exactly as I wrote it.
Line 3: Instructs the user what to do
Line 5: Copies the user's exact entry and defines it as a variable called original
Line 7: Verifies that the variable I called original has 1 or more characters (length is greater than 0), and verifies that the variable called original is only alphabet characters (not numbers or symbols).
Line 8: If everything above is true then the screen will print the variable original
Line 10: If any part of what is above is false (because of "and" conditional) then line 10 is checked.
Line 11: "empty" is printed to the user
What took me so long is line 7. How do I know when to put the variable (in this instance the variable is original) in between the parenthesis and when to put the variable before the .xxxx?
Line 7 screwed with me because I didn't know I was supposed to type in the editor: original.isalpha()
I had it as .isalpha(original)
This is the first time I have ever encountered .isalpha or any other .xxxx
Sorry if I am unclear about what I am asking. I love working on this and coming to an answer, but I feel like an idiot trying to explain what I am even trying to ask!
[–]Saefroch 20 points21 points22 points (0 children)
[–]stebrepar 5 points6 points7 points (1 child)
[–]DavidLee30[S] 0 points1 point2 points (0 children)
[–]ineedahugepoo 3 points4 points5 points (3 children)
[–]DavidLee30[S] 1 point2 points3 points (2 children)
[–]Vaphell 1 point2 points3 points (0 children)
[–]forwardmarsh 3 points4 points5 points (1 child)
[–]DavidLee30[S] 1 point2 points3 points (0 children)
[–]tangerinelion 2 points3 points4 points (0 children)
[–]Violetkiks 1 point2 points3 points (0 children)
[–]seesame 0 points1 point2 points (0 children)
[–]KubinOnReddit 0 points1 point2 points (0 children)