首页 > 解决方案 > how can I solve str' object does not support item assignmen?

问题描述

Thank you for your prompt reply. I posted it again because I wanted to hear the answer in more detail. I'm still inexperienced in Python, so I've implemented all nine cases of the Monty Hall dilemma. It works well until you press a function called "restart." The number of attempts, number of successes, success rates are good, and the number of cases works well without errors. The first thing I thought about was, If you press the button "restart!", the images of the three buttons that you first created will be replaced with question marks, and you will try to start over again by assigning random values to each button. When I first created this program,

 [button,button1,button2]=random.shuffle(['car','goat','goat'])

And I decided on all nine cases. for example,

if button=='car':
trival=trival+1
def button_funtion():
    global trival
    b=[button2,button3]
    x1,x2=random.sample(b,2)
    x1['image']=goat_image

Like this. Until I made the button "restart," the program worked as I thought. So if I press the "restart" button, Like

def restart():
global button
global button1
global button2
global trival
global count
button['image']=question mark
button1['image']=question mark
button2['image']=question mark
[button,button1,button2]=random.shuffle(['car','goat','goat'])
if button=='car'
    ...
    ...

I thought it would work well if I copied and pasted the nine cases that worked well before. But when you press the button here, you say,

 "Str' object does not support item assignment."

There was an error. how can I solve it?

标签: pythonstringbuttontkinterrandom

解决方案


推荐阅读