from random import randint
res=" "
i,j=0,len(s)-1
while i<len(s) and j>=i:
if randint(0,1) == 0: #randint(0,1)随机生成 0 或 1
res+=s[i]
i+=1
else:
res+=s[j]
j-=1
微信扫码预览、分享更方便