hey you guys im am a super newb on programming im just bearly getting the idea of varible and int and str;also about the only programming word play i know but anyways i started reading a tutorial and made me inspired to make a log in sort of game that could just be in the python module:ask for my password and username if true it would give me a nice greeting but if false then it would say invalid,but i have no clue of how to do this im could anybody show how this what this would look like.Ive tried looking around the internet but everything is about web logins and stuff.btw the tutorial i read was on raw_input and priting messages on screen
python login help
Started by BRUTAL, Dec 04 2010 09:43 PM
6 replies to this topic
#1
Posted 04 December 2010 - 09:43 PM
|
|
|
#2
Posted 05 December 2010 - 03:23 AM
Code may look like this:
I advice you not to learn programming via forums/tutorials/articles/faq. There are a lot of good books that can deeply explain everything from different points of view while on forum you can only get answer for particular problem. You can start with this book: Manning: Hello World!, but there are a lot of them on Internet.
login = raw_input('Login: ')
password = raw_input('Password: ')
if login == 'root' and password == 'root':
print('Hello, root')
else:
print('Invalid login or password')
I advice you not to learn programming via forums/tutorials/articles/faq. There are a lot of good books that can deeply explain everything from different points of view while on forum you can only get answer for particular problem. You can start with this book: Manning: Hello World!, but there are a lot of them on Internet.
#3
Posted 05 December 2010 - 03:55 AM
You can use 3. An Informal Introduction to Python — Python v3.1.3 documentation but I started with Python for Dummies book. ;)
PS - When you getting started to learn try to learn on version 3.
PS - When you getting started to learn try to learn on version 3.
Lost!
#4
Posted 05 December 2010 - 11:36 AM
thanks you guys for the replies,but ran into another problem if there login is wrong how would i get it to say wrong please try again or something to that effect an infinite amount of times until they got it right ive kinda got the concept of how to do it or i thought but it turns out im wrong could anybody help me again?
#5
Posted 05 December 2010 - 12:31 PM
You need infinitive loop (look at the forum logo :) until user enters right password:
while True: # infinitive loop
# code stays almost unmodified
login = raw_input('Login: ')
password = raw_input('Password: ')
if login == 'root' and password == 'root':
# user entered right login and password
# break the loop
break
else:
print('Invalid login or password. Please try again.')
# user reaches this point only if he entered right login and password
print('Hello, root')
#6
Posted 06 December 2010 - 07:08 PM
THANK YOU !!!!!!lol but, i do have one more question if they got the login wrong i want them to have to complete a math problem and then if there answer is right it returns them to the login options?
#7
Posted 08 December 2010 - 03:22 AM
You have to wrap login code to function and then call that function whenever you need:
As I said in my first answer you have to grab book for beginners and learn programming basics. I can't explain you everything in a few sentences.
def login():
# here goes login code
if answer != 'correct':
login()
As I said in my first answer you have to grab book for beginners and learn programming basics. I can't explain you everything in a few sentences.


Sign In
Create Account


Back to top









