Python Questions

Discussion in 'Computer Games and General Discussion' started by kevan, Dec 10, 2011.

Dec 10, 2011

Python Questions by kevan at 11:45 PM (1,167 Views / 0 Likes) 20 replies

  1. kevan
    OP

    Member kevan Imagination rules the world

    Joined:
    Dec 4, 2009
    Messages:
    1,378
    Location:
    Place
    Country:
    Australia
    Writing a little program since I'm bored...

    Code:
    import time
    bot = int(input("Anti-Bot Test: Enter a number under 5? "))
    if bot < 5:
    print ("Passed")
    else:
    print ("Failed")
    username = (input("Enter Username: "))
    password = (input("Enter Password: "))
    dob = (input("Date of Birth: "))
    print ("Review the following information")
    time.sleep(3)
    print ("You would like your username to be: "(username))
    I need it to at the end print whatever the user decided their username should be. Instead I get this error
    Code:
    Traceback (most recent call last):
    File "C:/Users/Jake/Desktop/Test", line 12, in 
    print ("You would like your username to be: "(username))
    TypeError: 'str' object is not callable
    Suggestions?

    Edit: Also if they enter a number higher than 5 with the bot test. The program goes on anyway. How do I make it, make them reenter the bot test?
     


  2. Zetta_x

    Member Zetta_x The Insane Statistician

    Joined:
    Mar 4, 2010
    Messages:
    1,844
    Country:
    United States
    I actually know 0 python, but I think I can help. The program continues when they enter a number greater than 5 because the only thing you have defined when a user inputs a number is print some characters.

    Instead fix it up so that it loops or exits if a number greater than 5 to prevent it from continuing.

    The problem with the str code is that username is a string and you can't call strings (something like that) (by the way you forgot the second quotes which doesn't relate to the problem).
     
  3. kevan
    OP

    Member kevan Imagination rules the world

    Joined:
    Dec 4, 2009
    Messages:
    1,378
    Location:
    Place
    Country:
    Australia
    Yeah I don't know how to loop it D:

    What do you mean by that?
     
  4. Zetta_x

    Member Zetta_x The Insane Statistician

    Joined:
    Mar 4, 2010
    Messages:
    1,844
    Country:
    United States
    I was looking at it wrong, not sure too much how python works.

    I have written primarily in C++ and SAS, not sure how to do a loop in python.

    It would be something like this:


    do while (bot >= 5)
    bot = int(input("Anti-Bot Test: Enter a number under 5? "))
    if bot < 5:
    print ("Passed")
    else:
    print ("Failed")

    end
     
  5. Zetta_x

    Member Zetta_x The Insane Statistician

    Joined:
    Mar 4, 2010
    Messages:
    1,844
    Country:
    United States
    SO when the user puts in 6, it stays in the do loop and puts in "Failed"
     
  6. kevan
    OP

    Member kevan Imagination rules the world

    Joined:
    Dec 4, 2009
    Messages:
    1,378
    Location:
    Place
    Country:
    Australia
    Yeah what you posted is what I need... I just don't know how to do that in Python :(
     
  7. Mazor

    Member Mazor Z80 master arch

    Joined:
    Feb 14, 2008
    Messages:
    547
    Country:
    Sweden
    Code:
    import time
    
    while True:
    value = int(raw_input("Anti-Bot Test: Enter a number under 5 (leave blank to quit): "))
    if not value:
    break
    elif value < 5:
    print "Passed"
    break
    else:
    print "Failed"
    
    if value:
    username = raw_input("Enter Username: ")
    password = raw_input("Enter Password: ")
    dob = raw_input("Date of Birth: ")
    print "Review the following information"
    time.sleep(1)
    print "You would like your username to be: " + username
    
    I don't have Python installed, but something like this is how I would write it and it should work.

    You should not use input() the way you did, use raw_input() instead. Your code actually took the input and evaluated it as Python code, see here. EDIT:
     
    1 person likes this.
  8. kevan
    OP

    Member kevan Imagination rules the world

    Joined:
    Dec 4, 2009
    Messages:
    1,378
    Location:
    Place
    Country:
    Australia
    Well you was missing a few brackets for print statements :P
    But anyway I hit this error after fixing those print statements
    Code:
    Traceback (most recent call last):
    File "C:/Users/Jake/Desktop/Revised Test", line 4, in 
    value = int(raw_input("Anti-Bot Test: Enter a number under 5 (leave blank to quit): "))
    NameError: name 'raw_input' is not defined
     
  9. Mazor

    Member Mazor Z80 master arch

    Joined:
    Feb 14, 2008
    Messages:
    547
    Country:
    Sweden
    No, the print statements were not missing anything. Putting parentheses around them is optional and unnecessary (I assume you meant parentheses since that's what you were using yourself and using brackets, eg [], is not correct).
     
  10. kevan
    OP

    Member kevan Imagination rules the world

    Joined:
    Dec 4, 2009
    Messages:
    1,378
    Location:
    Place
    Country:
    Australia
    Yeah I forgot to mention I was using Python 3 because I'm silly :P

    Code:
    Traceback (most recent call last):
    File "C:/Users/Jake/Desktop/Test 2", line 19, in 
    print ("You would like your username to be: ") + username
    TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
    Hitting that error again. Here is the current code I'm using

    Code:
    import time 
    
    while True: 
    value = int(input("Anti-Bot Test: Enter a number under 5 (leave blank to quit): ")) 
    if not value: 
    break 
    elif value < 5: 
    print ("Passed") 
    break 
    else: 
    print ("Failed") 
    
    if value: 
    username = input("Enter Username: ") 
    password = input("Enter Password: ") 
    dob = input("Date of Birth: ") 
    print ("Review the following information") 
    time.sleep(1) 
    print ("You would like your username to be: ") + username
    
     
  11. coolness

    Banned coolness PSN: Dutch_DarkLord

    Joined:
    Jun 14, 2009
    Messages:
    2,016
    Location:
    Rotterdam Bitches!!
    Country:
    Netherlands
    nice python code :)
    i created a python msn bot with a friend of mine
    old member of anonymous
     
  12. kevan
    OP

    Member kevan Imagination rules the world

    Joined:
    Dec 4, 2009
    Messages:
    1,378
    Location:
    Place
    Country:
    Australia
    Actually I'm just simulating a login process :P
    I still need help with this though D:
     
  13. Jiggah

    Member Jiggah GBAtemp Maniac

    Joined:
    Nov 9, 2002
    Messages:
    1,223
    Country:
    United States
    print ("You would like your username to be: %s" % (username))
     
  14. kevan
    OP

    Member kevan Imagination rules the world

    Joined:
    Dec 4, 2009
    Messages:
    1,378
    Location:
    Place
    Country:
    Australia
    Worked thank you so much :)
     
  15. kevan
    OP

    Member kevan Imagination rules the world

    Joined:
    Dec 4, 2009
    Messages:
    1,378
    Location:
    Place
    Country:
    Australia
    Code:
    import time
    
    while True:
    value = int(input("Anti-Bot Test: Enter a number under 5 (leave blank to quit): "))
    if not value:
    break
    elif value < 5:
    print ("Passed")
    break
    else:
    print ("Failed")
    
    if value:
    username = input("Enter Username: ")
    password = input("Enter Password: ")
    password2 = input("Re-enter Password: ")
    dob = input("Date of Birth: ")
    print ("Review the following information")
    time.sleep(1)
    print ("You would like your username to be: %s" % (username))
    
    
    This is my current code. I want it when the user re-enters the password. If it doesnt match the original password make them re-enter it.
    Yeah sorry Im a real newb at coding :(
     
  16. Qtis

    Member Qtis Grey Knight Inquisitor

    Joined:
    Feb 28, 2010
    Messages:
    3,762
    Location:
    The Forge
    Country:
    Antarctica
    After the password2 has been added do the following:
    Code:
    While password =! password2:
    print ("Second password doesn't match the first password")
    print ("Re-enter your original password")
    password2 = input("")
    
    That should fix it (if the =! isn't correct, it's !=).

    EDIT: If the first one was the problem, this will lead to a never ending loop. I may update it to work in that case, but now I'm off to Uni..
     
  17. kevan
    OP

    Member kevan Imagination rules the world

    Joined:
    Dec 4, 2009
    Messages:
    1,378
    Location:
    Place
    Country:
    Australia
    I'm confused...
    Where do I put that code again :unsure:
     
  18. Qtis

    Member Qtis Grey Knight Inquisitor

    Joined:
    Feb 28, 2010
    Messages:
    3,762
    Location:
    The Forge
    Country:
    Antarctica
    Code:
    import time
    
    while True:
    value = int(input("Anti-Bot Test: Enter a number under 5 (leave blank to quit): "))
    if not value:
    break
    elif value < 5:
    print ("Passed")
    break
    else:
    print ("Failed")
    
    if value:
    username = input("Enter Username: ")
    password = input("Enter Password: ")
    password2 = input("Re-enter Password: ")
    
    While password =! password2:
    print ("Second password doesn't match the first password")
    print ("Re-enter your original password")
    password2 = input("")
    dob = input("Date of Birth: ")
    print ("Review the following information")
    time.sleep(1)
    print ("You would like your username to be: %s" % (username))
    
    
    Something like that should work, if you want the bot to ask the password again until password = password2. Do note that what I said previously about the first password being wrong. If the person mistypes the first on in the first place, that leads to a never ending loop. This can be fixed by adding a second input on the While-loop.

    ps. I did my Python at Uni last spring, but we didn't use Python3. Thus sometimes my advice may be wrong because of that :glare:

    EDIT: well that went well.. I'll fix it if I can :P
     
  19. Jiggah

    Member Jiggah GBAtemp Maniac

    Joined:
    Nov 9, 2002
    Messages:
    1,223
    Country:
    United States
    Code:
    import time
    
    while True:
    value = int(input("Anti-Bot Test: Enter a number under 5 (leave blank to quit): "))
    if not value:
    break
    elif value < 5:
    print ("Passed")
    break
    else:
    print ("Failed")
    
    if value:
    username = input("Enter Username: ")
    password = input("Enter Password: ")
    password2 = input("Re-enter Password: ")
    
    while (password != password2):
    print ("Second password doesn't match the first password")
    print ("Re-enter your original password")
    password2 = input("")
    dob = input("Date of Birth: ")
    print ("Review the following information")
    time.sleep(1)
    print ("You would like your username to be: %s" % (username))
    
    Minor fixes.
     
  20. PsyBlade

    Member PsyBlade Snake Charmer

    Joined:
    Jul 30, 2009
    Messages:
    2,204
    Location:
    Sol III
    Country:
    Germany
    to quit a program use "exit(0)" instead of enclosing the rest in a big "if"
     

Share This Page