Beginner Question - Very Easy I'm Sure...

T

Todd_Calhoun

I'm trying to generate a random number, and then concetate it to a word to
create a password.

I get the number and assign it to a variable:

+++++++++++++++++++++++++++++
word = "dog"

import random
rannum = random.randrange(100,999)

str(rannum)

word + rannum
+++++++++++++++++++++++++++++

But when I try to concetate the two, I get an error saying:

++++++++++++++++++++++++++++
Traceback (most recent call last):
File "<pyshell#0>", line 1, in -toplevel-
list[1] + rannum
TypeError: unsubscriptable object
++++++++++++++++++++++++++++

Any suggestions?
 
J

Jaime Wyant

str() returns a string, it doesn't change rannum which is still a number...

try ->
rannum = str(rannum)

jw
 
B

Brian van den Broek

Todd_Calhoun said unto the world upon 2005-03-24 16:13:
I'm trying to generate a random number, and then concetate it to a word to
create a password.

I get the number and assign it to a variable:

+++++++++++++++++++++++++++++
word = "dog"

import random
rannum = random.randrange(100,999)

str(rannum)

word + rannum
+++++++++++++++++++++++++++++

But when I try to concetate the two, I get an error saying:

++++++++++++++++++++++++++++
Traceback (most recent call last):
File "<pyshell#0>", line 1, in -toplevel-
list[1] + rannum
TypeError: unsubscriptable object
++++++++++++++++++++++++++++

Any suggestions?

Hi,

you call str(rannum) but don't store it. Try it like this:
dog773

or,

HTH,

Brian vdB
 
T

Todd_Calhoun

Thanks for the tip. I knew it was something easy like that.


Brian van den Broek said:
Todd_Calhoun said unto the world upon 2005-03-24 16:13:
I'm trying to generate a random number, and then concetate it to a word
to create a password.

I get the number and assign it to a variable:

+++++++++++++++++++++++++++++
word = "dog"

import random
rannum = random.randrange(100,999)

str(rannum)

word + rannum
+++++++++++++++++++++++++++++

But when I try to concetate the two, I get an error saying:

++++++++++++++++++++++++++++
Traceback (most recent call last):
File "<pyshell#0>", line 1, in -toplevel-
list[1] + rannum
TypeError: unsubscriptable object
++++++++++++++++++++++++++++

Any suggestions?

Hi,

you call str(rannum) but don't store it. Try it like this:
dog773

or,

HTH,

Brian vdB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top