I need help - new to python - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

I need help - new to python

infa28oninfa28on Posts: 2Member
[b][red]This message was edited by infa28on at 2003-9-26 12:1:34[/red][/b][hr]
Thanks

Comments

  • infidelinfidel Posts: 2,900Member
    : Hi, I am taking a computer programming course and it requires us to use python. I have an assignment to write four programs - the first two I have completed however I am having trouble with the last two.
    :
    : LOOPS and IF STATEMENTS
    :
    : SAMPLE OUTPUT (including author/program information)
    : Program author: Barney Rubble
    : ID#: 1234567
    : Program 3 - LOOPS AND IF CONDITIONS
    : Password? unicorn
    : Password? opus
    : Password? hello
    : Welcome to the second half of the program!
    : What is your name? Barney
    : What a great name!
    :
    :
    : ALTERNATE OUTPUTS
    : What is your name? Cher
    : May I have your autograph, please?
    :
    : What is your name? Bill
    : Bill, that's a nice name
    :
    :
    : how do I loop - I can seem to find the info

    Have you ever programmed in a different language or are you completely new?

    Here are some links to the "official" python tutorial:

    "while" loops: http://www.python.org/doc/current/tut/node5.html#SECTION005200000000000000000

    "if" statements and "for" loops:
    http://www.python.org/doc/current/tut/node6.html

    Let me know if those don't help or if you're completely lost


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

  • infa28oninfa28on Posts: 2Member
    [b][red]This message was edited by infa28on at 2003-9-26 12:2:21[/red][/b][hr]

  • infidelinfidel Posts: 2,900Member
    : I have done some programming in visual basic ..a few years ago so it is a little foggy. I tried the Do / while bit but that didn't work.
    : After reading the post that you gave, I am still a bit lost. If I want to loop until the password for my program is correct - which loop do I use and how?
    : Sorry for sending you two messages.

    python doesn't have a do/while loop, just a while loop:

    [code]
    logged_in = False
    attempts = 0
    while not logged_in and attempts < 3:
    entered_value = raw_input('Password: ')
    if entered_value = ???:
    logged_in = True
    break
    else:
    print 'Invalid password.'
    attempts += 1

    if logged_in:
    print 'Logged in!'
    else:
    print 'Access denied!'
    [/code]

    Note that for this trivial example the password is hardcoded where the ??? is. Do not ever do this in real life.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

Sign In or Register to comment.