2 Replies - 2901 Views - Last Post: 18 September 2013 - 01:43 PM Rate Topic: -----

#1 gulaapan   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 12-August 13

Need to ask for input repeatedly

Posted 16 September 2013 - 09:29 AM

so what i wanna do is that if my raw_input doesn't contain more than 6 chars i want it to print"blablabla" and then return to the same raw_input before the user typed in the password...
don't know if i should use some kind of loop or objects, i don't even know what to call this problem in english...


i'll give you some code so u know what i mean and i'll explain what i want to do with a picture so you really understand :)

here's some code...(im working with python and mySQL atm)

print '(maximum of 12 characters)'
User_id = raw_input('Enter Username: ')

print 'minimum of 6 characters)'
Password = raw_input('Enter Password: ')

if len(Password) < 6:
    print 'An Error occured! please Enter a Password with a minimum of 6 characters'
else:
    print 'Your account have been succesfully created!'


sooo... there's nothing wrong with this simple code (maybe need some improvements but not the point right now.)

when i run it and type in a password using i.e 5 chars, it still saves it to my DB, what i want is

if len(Password) < 6:


i want it to return to the top of my script (see picture for awsome paintskills and what i mean)

sorry if it's hard to understand, but it's hard to explain when i don't understand it myself...

You may have some usefull links or something to share with me, i'm not asking for a straight answer, just want to learn.

Peace

here's the picture

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Need to ask for input repeatedly

#2 andrewsw   User is offline

  • no more Mr Potato Head
  • member icon

Reputation: 6957
  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: Need to ask for input repeatedly

Posted 16 September 2013 - 09:37 AM

Quote

Hello! No Error But Don't Know How To Get This To Work!

This is a nonsense title, please take the time to think of something sensible. I'll amend it on this occasion.

Yes, you need a loop to repeat statements. You might start by studying for and while loops here at wikibooks. A while is probably sensible for your current task.

There is also a Tutorials link at the top of this page.

Please study then attempt to modify your code. If you struggle you can always come back for assistance.

This post has been edited by andrewsw: 16 September 2013 - 09:38 AM

Was This Post Helpful? 0
  • +
  • -

#3 anbub4u   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-September 13

Re: Need to ask for input repeatedly

Posted 18 September 2013 - 01:43 PM

Hi,

Start with a while loop, python does not have a do...while, so you should use a logic to run the loop indefinitely and exit the loop when you reach your condition with in the loop.

Give a try, if you couldn't find, please post back.

Happy coding!
Anbu
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1