473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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?
Jul 18 '05 #1
3 1469
str() returns a string, it doesn't change rannum which is still a number...

try ->
rannum = str(rannum)

jw

On Thu, 24 Mar 2005 13:13:25 -0800, Todd_Calhoun <an**@anon.com> wrote:
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?

--
http://mail.python.org/mailman/listinfo/python-list

Jul 18 '05 #2
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:
import random
word = "dog"
rannum = random.randrange(100,999)
str(rannum) '773' type(rannum) <type 'int'> rannum = str(rannum)
new_word = word + rannum
print new_word dog773

or,
rannum = str(random.randrange(100,999))
word + rannum 'dog287'


HTH,

Brian vdB

Jul 18 '05 #3
Thanks for the tip. I knew it was something easy like that.
"Brian van den Broek" <bv****@po-box.mcgill.ca> wrote in message
news:ma*************************************@pytho n.org...
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:
import random
word = "dog"
rannum = random.randrange(100,999)
str(rannum) '773' type(rannum) <type 'int'> rannum = str(rannum)
new_word = word + rannum
print new_word dog773

or,
rannum = str(random.randrange(100,999))
word + rannum 'dog287'


HTH,

Brian vdB

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

44
by: lester | last post by:
a pre-beginner's question: what is the pros and cons of .net, compared to ++ I am wondering what can I get if I continue to learn C# after I have learned C --> C++ --> C# ?? I think there...
8
by: Bshealey786 | last post by:
Okay im doing my final project for my first computer science class(its my major, so it will be my first of many), but anyway im a beginner so im not to great with C++ yet. Anyway this is the error...
6
by: Alex | last post by:
Hello I am intersting in developing and my background is VBA used in Excel and a brief intro to Java. I am interested in learning beyond VB and feel that C++ would be a very good language to...
12
by: Joshua Rulz | last post by:
Hi, i want to learn to program im quite skilled with computers and want to learn c++. is there anyone who can teach me or tell me a good website to learn it? all replies will be appreciated.
18
by: mitchellpal | last post by:
Hi guys, am learning c as a beginner language and am finding it rough especially with pointers and data files. What do you think, am i being too pessimistic or thats how it happens for a beginner?...
20
by: weight gain 2000 | last post by:
Hello all! I'm looking for a very good book for an absolute beginner on VB.net or VB 2005 with emphasis on databases. What would you reccommend? Thanks!
4
by: chris19845 | last post by:
Hi there, I am a complete beginner so apologies if I make not a lot of sense. What I am trying to do is write a simple class, it has a class array variable named test of type String, ie private...
10
by: Roman Zeilinger | last post by:
Hi I have a beginner question concerning fscanf. First I had a text file which just contained some hex numbers: 0C100012 0C100012 ....
22
by: ddg_linux | last post by:
I have been reading about and doing a lot of php code examples from books but now I find myself wanting to do something practical with some of the skills that I have learned. I am a beginner php...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.