1

I am trying to run an old python code made with python 2.7(?) in python 3.3 and I'm stuck on updating the code to run. It keeps telling me "'range' object does not support item assignment" and for the life of I cannot figure it out. The code is for a "50 states trivia" game I found on google.

The error is at the line answer[i] = "%s " % flower[pick[i]].rstrip()

 pick = random.sample(range(50), 4)
print("The state flower of %s is:" % state[pick[0]])
answer = range(4)
for i in range(4):
 if i == 0:
 answer[i] = "%s " % flower[pick[i]].rstrip()
 else:
 answer[i] = "%s" % flower[pick[i]].rstrip()

BTW, this code is HERE

codeforester
43.7k21 gold badges121 silver badges157 bronze badges
asked May 8, 2013 at 8:06
1

1 Answer 1

5

Use:

answer = list(range(4))

to allow modifications

answered May 8, 2013 at 8:07
2
  • Thank you! But now I'm having all kinds of problems. Maybe someone could take a look at the original code (I added a link)? I'm getting a "local variable 'correct' referenced before assignment", and none of the multiple choice answers are displaying, just numbers. Commented May 8, 2013 at 9:18
  • @Andrew No worries, but sorry this site doesn't look at links, we need questions to be self contained. If you would like you can submit a new question :) Commented May 8, 2013 at 9:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.