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

Discussion in 'Python' started by Todd_Calhoun, Mar 24, 2005.

  1. Todd_Calhoun

    Todd_Calhoun Guest

    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)


    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?
    Todd_Calhoun, Mar 24, 2005
    1. Advertisements

  2. Todd_Calhoun

    Jaime Wyant Guest

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

    try ->
    rannum = str(rannum)

    Jaime Wyant, Mar 24, 2005
    1. Advertisements

  3. Todd_Calhoun said unto the world upon 2005-03-24 16:13:

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

    Brian vdB
    Brian van den Broek, Mar 24, 2005
  4. Todd_Calhoun

    Todd_Calhoun Guest

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

    Todd_Calhoun, Mar 25, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.