1
votes

I created the list with range numbers from -90 to 90. Now I need to make the random number from this list to appear in my question. Can anyone help me with that? This is where I got so far:

latitude = [n for n in range(-90,90)]
record = latitude[random.randrange(-90,90)]
question =['lati','country']
questions = random.choice(question)

if questions == 'lati':
    resp = raw_input('Is Wroclaw north of ' + record)

When I tried to run this I received an error saying that i cannot concatenate 'str' and 'int' objects.

3

3 Answers

2
votes

You cannot concatenate a string and a number. The best way to display it would be to use a format string, as follows:

resp = raw_input('Is Wroclaw north of %d' % record)
0
votes

you need to use str() here, because record is an integer, so you should convert it to string first before concatenation:

resp = raw_input('Is Wroclaw north of ' + str(record))

or use string formatting:

raw_input('Is Wroclaw north of {0}'.format(record))
-1
votes

Use record = random.randrange(-90,90) without a list. Or the next construstion if you really need a list.

random.choice([1,2,3])