I made this code.
def Replace place (a):
b = ''
for i in range (0, len(a)-1,2):
b += a[i+1] + a[i]
return b
If you change the position of '1234567' here, there is a problem that 563412 comes out and the last digit disappears. I want to print it out until the last digit, is there any way?
python
>>> def f(a):
b = ''
for i in range(0, len(a)-1, 2):
b += a[i+1]+a[i]
return b
>>> f("1234567")
'214365'
>>> def f(a):
b = ''
for i in range(0, len(a)-1, 2):
b = a[i+1]+a[i]+b
return b
>>> f("1234567")
'654321'
>>> def f(a):
b = ''
for i in range(0, len(a)-1, 2):
b = a[i]+a[i+1]+b
return b
>>> f("1234567")
'563412'
>>> def f(a):
b = ''
for i in range(0, len(a)+1, 2):
b = a[i:i+2]+b
return b
>>> f("1234567")
'7563412'
>>>
© 2024 OneMinuteCode. All rights reserved.