python - 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?
解决方案
推荐阅读
- css - 如何在css网格中获得交替高度?
- opengl - 如何在OpenGL中改变纹理的位置?
- sql - 如果插入子记录失败,Oracle 删除父记录
- css - 带有过渡模糊和移动文本的阴影过滤器
- azure-devops - Visual Studio 2019 如何从历史中获取以前的构建?
- python - 无法将 3d ply 文件图像转换为 2d 图像
- c# - 改变购物车总价格值 asp.net 核心
- python - 如何重置 NEAT Python 中的最大代数?
- snowflake-cloud-data-platform - 存储过程 - 多个 SQL 语句
- augmented-reality - 此图像缺少跟踪所需的属性