题解 | #密码游戏#

密码游戏

https://www.nowcoder.com/practice/36641ab168664384aff798ba7ce34bc1

num = input()
new_num = [(int(i) + 3) % 9 for i in num]
new_num[0], new_num[2] = new_num[2], new_num[0]
new_num[1], new_num[3] = new_num[3], new_num[1]
for i in new_num:
    print(i,end="")

mainly use the feature of list to solve this problem

# 其中 f 表示format
[f'ch_{i}' for i in range(10)]
# output
['ch_0', 'ch_1', 'ch_2', 'ch_3', 'ch_4', 'ch_5', 'ch_6', 'ch_7', 'ch_8', 'ch_9']

# 如果不加format
['ch_{i}' for i in range(10)]
['ch_{i}', 'ch_{i}', 'ch_{i}', 'ch_{i}', 'ch_{i}', 'ch_{i}', 'ch_{i}', 'ch_{i}', 'ch_{i}', 'ch_{i}']

全部评论

相关推荐

点赞 评论 收藏
分享
05-26 22:25
门头沟学院 Java
Java小肖:不会是想叫你过去把你打一顿吧,哈哈哈
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务