473,394 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Log in and password

1
I am trying to grasp the basics of "IF" statements in the python.
But for what ever reason cant.

Expand|Select|Wrap|Line Numbers
  1. username= raw_input('Username for this program : ')
  2.  
  3. if username < 23:
  4.         username = 23
  5.         print 'I am sorry you are not the user of this program.'
  6. elif username == 23:
  7.         print "Welcome user #23"
  8. elif username != 23:
  9.         exit
  10. else:
  11.         exit
Now whats that's suppose to do is ask for user name much like it dose, and if it is equal to the user name of twenty three then precede to asking for the password. (in this case the pasword uses the same if statement), although if you get the user name wrong then if will not let you go any further and will exit the program, as seen in the lines were else: exit.
although when i run the application, if i get the username wrong it moves on to the password ands that even if i hit enter for both will allow me to enter the program....

I need it so that if you get the user name wrong you will be exitied out of the program and if you get the password wrong, same deal...or....

heres the or.

If you get the user name wrong to GOTO what ever line the program starts on...
but that GOTO can only be applied to the user name.
Jan 25 '08 #1
2 1358
I am trying to grasp the basics of "IF" statements in the python.
But for what ever reason cant.

Expand|Select|Wrap|Line Numbers
  1. username= raw_input('Username for this program : ')
  2.  
  3. if username < 23:
  4.         username = 23
  5.         print 'I am sorry you are not the user of this program.'
  6. elif username == 23:
  7.         print "Welcome user #23"
  8. elif username != 23:
  9.         exit
  10. else:
  11.         exit
Now whats that's suppose to do is ask for user name much like it dose, and if it is equal to the user name of twenty three then precede to asking for the password. (in this case the pasword uses the same if statement), although if you get the user name wrong then if will not let you go any further and will exit the program, as seen in the lines were else: exit.
although when i run the application, if i get the username wrong it moves on to the password ands that even if i hit enter for both will allow me to enter the program....

I need it so that if you get the user name wrong you will be exitied out of the program and if you get the password wrong, same deal...or....

heres the or.

If you get the user name wrong to GOTO what ever line the program starts on...
but that GOTO can only be applied to the user name.
The main problem I notice with your code is that you are trying to compare a string and an integer in your IF statements. The "raw_input" function returns a string, so you must either compare strings or cast the "username" as in integer.

This might point you in the right direction:
Expand|Select|Wrap|Line Numbers
  1. import sys
  2.  
  3. username= raw_input('Username for this program : ')
  4.  
  5. if username == '23':
  6.     print "Welcome user #23"
  7. else:
  8.     print 'I am sorry you are not the user of this program.'
  9.     sys.exit()
  10.  
  11. password = raw_input('Password : ')
  12.  
  13. if password == 'rosebud':
  14.     print "User authenticated"
  15. else:
  16.     print 'Incorrect password'
  17.     sys.exit()
Jan 26 '08 #2
Or, if i'm not mistaken, you could just take the string you get from raw_imput and turn that into an integer.

(this code has not be tested and i am a rookie, so there could be an error)...

username_string = raw_input("Enter your usernamer: ")

unsername_integer = int(username_string)

this way you can computer numbers to numbers rather than text to numbers.
Jan 26 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jill Elaine | last post by:
I am building an Access 2002 frontend with linked tables to an encrypted Paradox 7 database. When I first create these linked tables, I'm asked for the password to the encrypted Paradox database,...
10
by: Fabrizio | last post by:
(Sorry for the crosspost, but I really don't know which is the right newsgroup!) Hi all, I try to change the password to a user that as to change the password at first logon: try {
5
by: scorpion53061 | last post by:
is it possible to set the database password that you can set in access for a database from a vb.net application?
26
by: David Garamond | last post by:
I read that the password hash in pg_shadow is salted with username. Is this still the case? If so, since probably 99% of all PostgreSQL has "postgres" as the superuser name, wouldn't it be better...
8
by: Katash | last post by:
Hello, I am new to PHP and am working on a login system for my site, currently supplied passwords are passed to MySQL and stored as md5 hashes, my question is :- seeing as md5 is 1 way only what...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.