当前位置:网站首页>出现“TypeError: ‘str‘ object does not support item assignment”的原因
出现“TypeError: ‘str‘ object does not support item assignment”的原因
2022-07-21 03:22:00 【今天不学习,明天变腊鸡】
1.翻译
‘TypeError: ‘str’ object does not support item assignment’:
类型错误: ‘str’ 对象不支持项目赋值
**就是可以遍历字符串,但是字符串中的每一个值都是不可以更改的,除非你再赋值一次
str = input()
str_length = len(str)
#数字、字符串和元组是不可变对象
for i in range(0,str_length):
str[i] = int(str[i])
print(str)
练习:
题目:
描述
牛牛和牛妹一起玩密码游戏,牛牛作为发送方会发送一个4位数的整数给牛妹,牛妹接收后将对密码进行破解。
破解方案如下:每位数字都要加上3再除以9的余数代替该位数字,然后将第1位和第3位数字交换,第2位和第4位数字交换。
请输出牛妹破解后的密码。
输入描述:
输入一个四位数的整数。
输出描述:
输出破解后的密码,以四位数的形式。
示例1
输入:
1234
复制
输出:
6745
复制
备注:
输入不会有前置0,但是输出要保持前置0
题解:
str = input()
count = []
for i in str:
count.append(int(i))
for i in range(0,4):
count[i] = count[i] + 3
count[i] = count[i] % 9
print(count[2],end='')
print(count[3],end='')
print(count[0],end='')
print(count[1],end='')
边栏推荐
- toast_tuple_threshold的疑问
- JMeter学习笔记003-JMeter之CSV参数化
- Create high-performance applications and continuously optimize the user experience
- [cloud native kubernetes] how to use health check under kubernetes cluster
- [QT入门篇]信号槽机制
- NFS服务配置
- FTP服務配置
- [QNX hypervisor 2.2 user manual]8.6 interrupt
- 软件测试面试题:如何测试一个纸杯?
- 【信息检索】信息检索系统实现
猜你喜欢
hcip第二天实验
Distributed High availability and high scalability index
MYSQL09_ Elaborate on database data types
According to the framework's swagger interface document
QT(37)-mosquitto-MQTT客户端
Create high-performance applications and continuously optimize the user experience
分布式.高并发概念和设计目标
Light the first LED
MYSQL06_sql99的7种JOIN操作、union all
[information retrieval] implementation of information retrieval system
随机推荐
2022 software testing skills jmeter+ant+jenkins continuous integration and test report generation tutorial
外设驱动库开发笔记44:DDC114 ADC驱动
KingbaseES V8R6有什么办法,默认不读取sys_catalog下的系统视图?
PyTorch 深度学习实践 第2讲/作业(Linear Model)
Don't want to wake up because it's delicious
MYSQL06_ Seven join operations and union all of sql99
打造高性能应用,持续优化用户体验
LogMAP: logic based and scalable ontology matching
MYSQL07_获取日期函数、聚合函数、字符串函数
toast_tuple_threshold的疑问
Time series data: prediction
Create high-performance applications and continuously optimize the user experience
Configuration du Service FTP
【LeetCode】1260. 二维网格迁移
不想醒来因为好吃
NFT: the core of digital ownership
中国五氯化磷市场调研与投资预测报告(2022版)
Software testing interview questions: black box testing and white box testing are two basic methods of software testing. Please explain their advantages and disadvantages respectively!
分布式.高性能
4、security之自定义数据源