Merge two strings with alternate chars as output

后端 未结 5 1321
悲哀的现实
悲哀的现实 2021-01-17 01:53

I got the task to alternately combine the letters of two strings with the same length.

For example:

Inputstring 1: \"acegi\"

Inputstring 2: \"bdfhj\         


        
5条回答
  •  南方客
    南方客 (楼主)
    2021-01-17 02:09

    Get a and b with input or however you want. No need to copy that. The point is the code.

    a = 'acegi'
    b = 'bdfhj'
    
    c = ''
    for i in range(len(a)):
        c += a[i] + b[i]
    
    print(c)
    

    Result is:

    abcdefghij
    

提交回复
热议问题