题解 | #密码游戏#

密码游戏

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}']

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-21 13:38
8月实习会变多吗现在还没找到实习该怎么办...回复的hr好少
码农索隆:3-4月就要开始找,基本上6月份就发offer,7月初已经开始暑期实习了。
点赞 评论 收藏
分享
盖茨伯爵:一样兄弟,我从4月开始发到现在了,都三四百个了
无实习如何秋招上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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