IAmRaspbian
Posts: 12
Joined: Tue Dec 25, 2012 9:57 am

goAgain?

Tue Mar 19, 2013 7:59 am

I've been trying to create a very simple password system, but when I ran it the first time... I noticed a problem, I didn't know how to make it go back to the start. So, should I be using goAgain?

If it helps, here's the code;

Code: Select all

password = "password"
attempt = raw_input("Enter password: ")
if attempt == password :
    print "Correct Password"

else :
    print "Incorrect Password"
Thanks on advance,

ejfield
Posts: 17
Joined: Fri Oct 19, 2012 10:21 am

Re: goAgain?

Tue Mar 19, 2013 8:26 am

Try this:

Code: Select all

password = "password"
attempt = ""
while attempt != password :
    attempt = input("Enter password: ")
    print ("Incorrect Password")
print( "Correct Password")
Note that the two print statements are in Python3 format - you will probably want to remove the brackets.

...and raw_input changed to input for the same reason!
Last edited by ejfield on Tue Mar 19, 2013 8:28 am, edited 1 time in total.

IAmRaspbian
Posts: 12
Joined: Tue Dec 25, 2012 9:57 am

Re: goAgain?

Tue Mar 19, 2013 8:27 am

Thanks, ejfield :)

IAmRaspbian
Posts: 12
Joined: Tue Dec 25, 2012 9:57 am

Re: goAgain?

Tue Mar 19, 2013 8:32 am

Completely off topic question , but what does != do?

gordon77
Posts: 5133
Joined: Sun Aug 05, 2012 3:12 pm

Re: goAgain?

Tue Mar 19, 2013 8:35 am

It means NOT equal to.

IAmRaspbian
Posts: 12
Joined: Tue Dec 25, 2012 9:57 am

Re: goAgain?

Tue Mar 19, 2013 8:37 am

Thanks Gordon

IAmRaspbian
Posts: 12
Joined: Tue Dec 25, 2012 9:57 am

Re: goAgain?

Tue Mar 19, 2013 8:45 am

How to I use wait? I find when I run it, everything rifles through, is it wait(10) and ":" at the end, or have I got it all wrong?

Code: Select all

password = "password"
attempt = ""
while attempt != password :
    attempt = input("Enter password: ")
    wait(10)print ("Incorrect Password"):
wait(10)print( "Correct Password"):

gordon77
Posts: 5133
Joined: Sun Aug 05, 2012 3:12 pm

Re: goAgain?

Tue Mar 19, 2013 9:05 am

Try time.sleep(x)

Add import time
at the start

And use time.sleep(x)

X = seconds

IAmRaspbian
Posts: 12
Joined: Tue Dec 25, 2012 9:57 am

Re: goAgain?

Tue Mar 19, 2013 9:17 am

I've ran into a problem with time.sleep(X)

Code: Select all

time.sleep(10) print "Correct Password"
It tells me the print, is an invalid syntax. Do I need to put the

Code: Select all

time.sleep(10)

on it's own line?

gordon77
Posts: 5133
Joined: Sun Aug 05, 2012 3:12 pm

Re: goAgain?

Tue Mar 19, 2013 9:18 am

Yes

IAmRaspbian
Posts: 12
Joined: Tue Dec 25, 2012 9:57 am

Re: goAgain?

Tue Mar 19, 2013 9:21 am

Thanks :D

IAmRaspbian
Posts: 12
Joined: Tue Dec 25, 2012 9:57 am

Re: goAgain?

Tue Mar 19, 2013 9:29 am

One final question, how do I make the password invisible, or dots?

Here's the coding so far;

Code: Select all

import time
password = "password"
attempt = raw_input("Enter password: ")
if attempt == password :
    time.sleep(0.5)
    print "Correct Password"

else :
    time.sleep(0.5)
    print "Incorrect Password"

mefarmer
Posts: 36
Joined: Wed Mar 13, 2013 10:53 pm

Re: goAgain?

Tue Mar 19, 2013 1:56 pm

Hello IAmRaspbian,
I see you are just now learning Python and I think that is great!
It's always good for us old timers to see someone join in our fun.
From the level of questions you are asking it looks like:
1) you are thinking about how to structure your program
2) having problems with the syntax
3) need to learn some of Pythons modules
I am sure many on this forum would love to answer all your questions but...
we would be cheating you out of the thrill of learning it yourself.
Those first moments when you type in a program and runs as expected are awesome.
Experience will come through practice. Check out this website http://www.learnpython.org/
You can go through the tutors and type into the interpreter at the bottom and see the results.
There are many resources available to learn, so look around for one that fits your style.

Return to “Python”