original.isalpha() does exactly what you expected it to do. It returned false when you gave “B1” as input.
Should the reply not have said False?
It doesn’t say “False” because you haven’t told it to. You told the interpreter to print “empty”. As you can see here:
You may still be confused, so I’m going to go through your script step by step.
original = raw_input("What is yout name")
This tells the interpreter to assign
original whatever value you write into stdin (what you type on your keyboard). You probably already know how to use it.
if len(original) > 0 and original.isalpha():
This tells the interpreter to execute whatever instructions is written below it(the indentation marks what code should be run) as long as the condition given is true (you probably already knew that too).
Now let’s try to deduce if the condition will be true or false.
len(original) > 0
This checks if you’ve entered anything at all. Let’s say you typed “B1”. This is true so we already substitute that small condition through a boolean in the big condition:
True and original.isalpha()
Now let’s look at
This returns true if there are only letters in
original. Now, this is not the case with “B1”, so we now know it’s false. Let’s look at our condition again:
True and False
True and False is false. Because, for the output of an and gate to be true, all the inputs also need to be true. As this is not the case, the condition is false. Let’s look at our if statement now:
This won’t execute the code written below it so we are going to look at the next command:
This tells the interpreter that if the last condition was false to execute the code below it. As the last condition was false, it is what we are going to do.
This tells to write “empty” to stdout (in this case our screen). So, now we read “empty” which is exactly what you said happened.
So this code simply says if input was given and the input is only constituted of letters, output the input. If that was not the case, it should output “empty”.