Gaming Python Questions

kevan

Imagination rules the world
OP
Member
Joined
Dec 4, 2009
Messages
1,378
Trophies
0
Age
29
Location
Place
Website
Visit site
XP
496
Country
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?
 

Zetta_x

The Insane Statistician
Member
Joined
Mar 4, 2010
Messages
1,844
Trophies
0
Age
34
XP
574
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).
 

Zetta_x

The Insane Statistician
Member
Joined
Mar 4, 2010
Messages
1,844
Trophies
0
Age
34
XP
574
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
 

Mazor

Z80 master arch
Member
Joined
Feb 14, 2008
Messages
547
Trophies
0
Age
16
Website
Visit site
XP
245
Country
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:
 
  • Like
Reactions: 1 person

kevan

Imagination rules the world
OP
Member
Joined
Dec 4, 2009
Messages
1,378
Trophies
0
Age
29
Location
Place
Website
Visit site
XP
496
Country
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
 

Mazor

Z80 master arch
Member
Joined
Feb 14, 2008
Messages
547
Trophies
0
Age
16
Website
Visit site
XP
245
Country
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).
 

kevan

Imagination rules the world
OP
Member
Joined
Dec 4, 2009
Messages
1,378
Trophies
0
Age
29
Location
Place
Website
Visit site
XP
496
Country
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
 

kevan

Imagination rules the world
OP
Member
Joined
Dec 4, 2009
Messages
1,378
Trophies
0
Age
29
Location
Place
Website
Visit site
XP
496
Country
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 :(
 

Qtis

Grey Knight Inquisitor
Member
Joined
Feb 28, 2010
Messages
3,817
Trophies
2
Location
The Forge
XP
1,737
Country
Antarctica
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 :(
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..
 

Qtis

Grey Knight Inquisitor
Member
Joined
Feb 28, 2010
Messages
3,817
Trophies
2
Location
The Forge
XP
1,737
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
 

Jiggah

Well-Known Member
Member
Joined
Nov 9, 2002
Messages
1,223
Trophies
0
Website
Visit site
XP
279
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.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    Maximumbeans @ Maximumbeans: butte