If the user enters only one character, I want it to prompt for the name again; otherwise print the persons name in ASCII. Instead what is happening is it's printing the name depending on how many characters are in the name ?

nameAsk = raw_input("What is your name?")
for name in nameAsk:
  if (len(name)>=2):
    print(ord(name))
  else:
    raw_input(nameAsk)

I suggest you read this first.

https://wiki.python.org/moin/WhileLoop

So tossing what is above why not do a while instead?

n = raw_input("Please enter 'hello':")
while len(n.strip()) < 3 :
    n = raw_input("Please enter 'hello':")

Can't you do else within while loops ?

You wrote raw_input(nameAsk) instead of raw_input('What is your name'). I would also use a while loop. The idiom while True means repeat indefinitely, so my loop runs until the break statement exits the loop. The advantage is that I don't have to write the raw_input() statement twice.

while True:
    name = raw_input('What is your name: ').strip()
    if len(name) >= 2:
        break

for c in name:
    print ord(c),

By the way, why are you learning with python 2 instead of python 3 ?

Thanks, wasn't aware you could append a string operation; then again strip() is a string operation :)
I'm learning both; some program API I'll be using only use Python 2.

As long as you think the result of an expression is a string, you can append a string operation. For example the result of raw_input('name? ').strip() is a string, so I can append .capitalize(). The same applies to any data type.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.