Author Topic: Trying to learn Python.  (Read 1019 times)

Well, I tried making a calculator but apparently that's built in already, and i'm not sure what else to make and I only know so little things.
Can anyone drop me some tips or tell me what to make that is simple?

make a tax calculator



anything but a calculator pls
make a scientific calculator to replace the default windows one.

Make a little program that has a database of usernames and passwords then you can log in and do stuff like delete accounts as admin, logout or message other users.

Code: [Select]
import time #imports database duh
database = [
    {'user','123'},{'admin','456'}  #what the database variable is, it's made like this so later i can just easily use {user,pass} as a check
    ]

value = 1 #for the loop. while this value is still equal to one and doesn't change the while value ==1: line below doesn't stop
while value == 1: #loops while the var above is 1
    time.sleep(1) #pause for 1 second i think.
    user = input("Username: ") #gets user input from keyboard and stores it for later. the whole input function is defined as 'user'
    time.sleep(1) #pause again
    password = input("Password: ") #gets the user input from keyboard for password and stories it again. defined as 'password'
    time.sleep(1) #pause again
    if {user,password} in database: #checks to see if Username and Password var from above are in the databse itself in the same order
            value = 2 #if above is true then value changes to 2 so the loop stops
            print("Welcome " + user) #prints success
            break #ends program
    else: #when the if statement above fails it goes here
        print("Incorrect Login. Try again") #prints failure
#and the program keeps repeating due to the while value == 1 line
#Fixed
« Last Edit: April 25, 2013, 12:42:36 PM by Blockzillahead »


I am confused by this simple peice of code. I don't know much about Python, just pretty much import, if, elif, variables, and some other small stuff.

Code: [Select]
database = [
    {'user','123'},{'admin','456'}
    ]

what the hell are you even

Code: [Select]
users = (
    ('user', '123'),
    ('admin', '456')
)

or just use a list of instances of an "User" class

Code: [Select]
value = 1
while value == 1:

.. why 1
have you never heard of booleans

value = True

and what kind of a variable name is value; why not something like run?

Code: [Select]
while value == 1:

please don't be the person who writes this kind of thing:

while len(items) is not 0:

when you can just do this:

while items:

Code: [Select]
   time.sleep(1)

why these delays

Code: [Select]
   if {user,password} in database:

I haven't studied Python 3 that much but I'm pretty sure that making sets with {} only works in "inline generators"
unless you were trying to make a tuple/list, which is probably the case, but this would be invalid

Code: [Select]
           value == 2

uhm
what

you're comparing value to 2 as a statement
even if you were trying to set it, why would you be doing this
break would already end the loop, no need to change value

Code: [Select]
//Fixed

what
this is invalid comment syntax

what the hell are you even

Code: [Select]
users = (
    ('user', '123'),
    ('admin', '456')
)

or just use a list of instances of an "User" class

.. why 1
have you never heard of booleans

value = True

and what kind of a variable name is value; why not something like run?

please don't be the person who writes this kind of thing:

while len(items) is not 0:

when you can just do this:

while items:

why these delays

I haven't studied Python 3 that much but I'm pretty sure that making sets with {} only works in "inline generators"
unless you were trying to make a tuple/list, which is probably the case, but this would be invalid

uhm
what

you're comparing value to 2 as a statement
even if you were trying to set it, why would you be doing this
break would already end the loop, no need to change value

what
this is invalid comment syntax

I'm sorry I'm still new to python too :(

wow port ur coding knowledge turns me ON~