A PHP Error was encountered

Severity: Warning

Message: fopen(/var/cpanel/php/sessions/ea-php56/PHPSESSIDgs0bfe0pqpslb8b56d0aipuf1gmoqri3): failed to open stream: No space left on device

Filename: drivers/Session_files_driver.php

Line Number: 174

A PHP Error was encountered

Severity: Warning

Message: session_start(): Cannot send session cookie - headers already sent by (output started at /home/nerd/public_html/system/core/Exceptions.php:271)

Filename: Session/Session.php

Line Number: 144

A PHP Error was encountered

Severity: Warning

Message: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/nerd/public_html/system/core/Exceptions.php:271)

Filename: Session/Session.php

Line Number: 144

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /home/nerd/public_html/system/core/Exceptions.php:271)

Filename: controllers/Questions.php

Line Number: 268

Append new string in the middle of a given string using python programming
Q:

Append new string in the middle of a given string using python programming

0

Append new string in the middle of a given string

Given two strings, s1 and s2. Write a program to create a new string s3 by appending s2 in the middle of s1.

Given:

s1 = "Ault"
s2 = "Kelly"

Expected Output:

AuKellylt

All Answers

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /home/nerd/public_html/system/core/Exceptions.php:271)

Filename: questions/question_for_visitors.php

Line Number: 568

need an explanation for this answer? contact us directly to get an explanation for this answer

Hint:

  • Use built-in function len(s1) to get the string length.
  • Next, get the middle index number by dividing string length by 2.

Solution:

  • First, get the middle index number of s1 by dividing s1’s length by 2
  • Use string slicing to get the character from s1 starting from 0 to the middle index number and store it in x
  • concatenate x and s2x = x + s2
  • concatenate x and remeaning character from s1
  • print x
def append_middle(s1, s2):
    print("Original Strings are", s1, s2)

    # middle index number of s1
    mi = int(len(s1) / 2)

    # get character from 0 to the middle index number from s1
    x = s1[:mi:]
    # concatenate s2 to it
    x = x + s2
    # append remaining character from s1
    x = x + s1[mi:]
    print("After appending new string in middle:", x)

append_middle("Ault", "Kelly")

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now

A PHP Error was encountered

Severity: Warning

Message: Unknown: Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/cpanel/php/sessions/ea-php56)

Filename: Unknown

Line Number: 0