题解 | #密码游戏#
密码游戏
https://www.nowcoder.com/practice/36641ab168664384aff798ba7ce34bc1
num = int(input()) num_thousand = num//1000 num_hundred = (num//100)%10 num_tens = (num//10)%10 num_ones = num%10 num_thousand_2 = (num_thousand+3)%9 num_hundred_2 = (num_hundred+3)%9 num_tens_2 = (num_tens+3)%9 num_ones_1 = (num_ones+3)%9 lst=[num_tens_2,num_ones_1,num_thousand_2,num_hundred_2] print(lst[0],lst[1],lst[2],lst[3],sep='')
我的思路主要是将一个四位数对应的千位、百位、十位,个位的数字输出,并且分别加3再除以9取余,用列表将数字对应的位置直接调换,然后用不带空格print方法,直接输出这个四位数


