-1

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.

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153

3 Answers3

2

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)
Steve Mayne
  • 22,285
  • 4
  • 49
  • 49
0

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))
Ashwini Chaudhary
  • 244,495
  • 58
  • 464
  • 504
-1

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

random.choice([1,2,3])
SWAPYAutomation
  • 693
  • 4
  • 11