473,545 Members | 666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.randrang e(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 1479
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.co m> 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.randrang e(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.randrang e(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.randrang e(100,999)
str(rannum) '773' type(rannum) <type 'int'> rannum = str(rannum)
new_word = word + rannum
print new_word dog773

or,
rannum = str(random.rand range(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******** *************** **************@ python.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.randrang e(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.randrang e(100,999)
str(rannum) '773' type(rannum) <type 'int'> rannum = str(rannum)
new_word = word + rannum
print new_word dog773

or,
rannum = str(random.rand range(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
4136
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 must be many know the answer here. thanks
8
1997
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 msg that im getting: "Error executing cl.exe" this is the code that I have, but I know whats causing it, ill just show you the whole thing first...
6
1560
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 get to know and give a lot of flexibility (if not tough to learn). I would like some advice on the merits of learning C++ versus C# or Visual...
12
2093
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
2903
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? Are there better languages than c for a beginner? For instance visual basic or i should just keep the confidence of improving?
20
2253
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
1350
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 String test; I need to write a constructor that will take a string Array as its argument then assign it to the test variable? I am sure it is very...
10
4431
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
18111
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 programmer and looking for a starting point in regards to practical projects to work on. What are some projects that beginner programmers usually...
0
7656
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7807
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7419
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7756
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5326
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3442
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1879
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.