How you test your code depends on many different things: program size, complexity of what you’re testing, resources available, your knowledge of what needs to be tested, lots of things! For that reason, it can be difficult to know how to test a program and even more difficult to know when you’ve done enough testing to say with any certainty that the code is ready to go! As a general rule of thumb, though, for smaller projects like these:
Run your code whenever you add a new feature. That can be as small as a single word of code, a line, or an entire block of code. Introducing something new into a previously working program is a good reason to test!
Why does this code return Empty if my input is: “Hey there” But it works if it is like this: “Heythere” in other words whenever we have a space it returns empty…
print ‘Welcome to the Pig Latin Translator!’
Start coding here!
original = raw_input("Enter a word: ")
if len(original) > 0 and original.isalpha():
print original
else:
print (“Empty”)
Because the space in your input is seen as a character but not and alphabet letter so when .isalpha() is ran it sees that space as a reason to run the else statement and print empty
Throughout the entire Pig Latin exercise so far, the website has forced me to use ‘Solution’ to advance instead of giving me the option to press ‘Next’ after I’ve written the proper code. No matter how many times I test my code, and no matter how many variations I make to minor things like double quotes vs. single quotes, spacing, etc., I literally cannot complete each exercise without Codecademy forcing me to ask for the solution. Then, when I click on ‘Solution,’ the website simply produces the exact same code I already have, down to every last little detail. I am wondering what the reason for this buggy behavior might be - any ideas? My only thought so far is that maybe it has something to do with my Internet connection being poor.
EDIT: Switched from Firefox to Chrome and it started working properly. It was a browser issue. Would be nice for someone to be made aware of this incompatibility with Firefox.
Are there similar methods like .isalpha() which can be used to to accept, for example: only integers, or only special characters etc.
I also wonder whether I can use such methods to ensure that the user input essentially contains multiple type of characters (e.g. integer and alphabets are both compulsory) as in the making of strong passwords.
Alphabetic characters are those characters defined in the Unicode character database as “Letter”, i.e., those with general category property being one of “Lm”, “Lt”, “Lu”, “Ll”, or “Lo”.
More on those “Letters” of which there are more than 120,000, here.
Neither is True because of the mix of alpha and white space.
We can make a list of the entire input, and iterate it by character.
>>> a = "abc1 def2 ghi3"
>>> b = list(a)
>>> c = [x for x in b if x.isalpha() or x.isdigit() or x.isspace()]
>>> c
['a', 'b', 'c', '1', ' ', 'd', 'e', 'f', '2', ' ', 'g', 'h', 'i', '3']
>>> d = ''.join(c)
>>> d == a
True
>>>
Since the final string is the same as the original one, there were no rejected characters.
>>> a = "$abc1 %def2 &ghi3"
>>> b = [x for x in list(a) if x.isalpha() or x.isdigit() or x.isspace()]
>>> ''.join(b) == a
False
>>>
As a side note, there is no such thing as a negative length, only a negative displacement. Length is scalar and always positive, or zero in the absence of any.
Hi,
I’m currently working on the Pig Latin translator and I got to the point where I was supposed to type a word into the console, but whenever I try to type, nothing happens. I checked multiple times to make sure my code is correct, and I clicked on the console before I started typing, but nothing comes up when I type on my computer’s keyboard. Could you please help?
even I had the same problem, but I was using safari browser. my code was correct, even after running, they y\told me to try again. and I was forced to take VIEW SOLUTION option every single time. please fix this bug / problem
Considering this lesson expects only one word, there should not be any spaces. If we are to allow spaces then we will need extra logic to check first for letters, and then for spaces. A one-step method won’t be able to do the job.
Hola , cuando llegue a este punto siempre me arrojaba error . Se agoto el tiempo de ejecución o alguna cosa ,y no me devolvía mi hola. Tome en cuenta lo que tú escribiste y le agregue or y me devolvió mi hola y ahora pude continuar.
print ‘Welcome to the Pig Latin Translator!’
Start coding here!
original = raw_input(“Enter a word:”)
if len(original) > 0 and original.isalpha() or original.isaspce():
print original
else:
print “empty”